首頁  >  文章  >  後端開發  >  C#使用Free Spire.Presentation實作對PPT插入與編輯以及刪除表格

C#使用Free Spire.Presentation實作對PPT插入與編輯以及刪除表格

黄舟
黄舟原創
2017-10-01 07:24:573098瀏覽

小編發現使用.NET元件-Free Spire.Presentation,在C#中加入該產品DLL文件,可以簡單快速地實現對簡報的表格插入、編輯和刪除等操作,具體實作程式碼大家參考下本文吧

現代學習與辦公室當中,常常接觸到表格的運用,像是各種單據、報表、帳戶等等。在PPT簡報中同樣不可避免的應用到各種資料表格。對於在PPT中插入表格,我發現了一個新方法,不過我用到了一款免費的.NET組件——Free Spire.Presentation,在C#中添加該產品DLL文件,可以簡單快速地實現對演示文稿的表格插入、編輯和刪除等操作。有需要的話可以在下面的網址下載:https://www.e-iceblue.cn/Downloads/Free-Spire-Presentation-NET.html

1.插入表格

步驟一:建立一個PowerPoint文件


  Presentation ppt = new Presentation();
   ppt.SlideSize.Type = SlideSizeType.Screen16x9;

步驟二:初始化一個ITable實例,並指定位置、行數和列數、行高與列寬           


double[] widths = new double[] { 100, 100, 100, 100, 100 };
   double[] heights = new double[] { 15, 15, 15, 15, 15 };
   ITable table = ppt.Slides[0].Shapes.AppendTable(80, 80, widths, heights);

步驟三:設定為表格設定內建格式       ”>宣告並初始化一個String[,]陣列       


#
 table.StylePreset = TableStylePreset.LightStyle1Accent2;

步驟六:儲存文件          


 string[,] data = new string[,]
{
   {"排名","姓名", "销售额","回款额","工号"},
   {"1","李彪","18270","18270","0011"},
   {"2","李娜","18105","18105","0025"},
   {"3","张丽","17987","17987","0008"},
   {"4","黄艳","17790","17790","0017"},
};
下列PPT文件效果


2.刪除表格行與欄位

步驟一:初始化一個Presentation實例並載入一個PowerPoint文件        #

 ppt.SaveToFile("创建表格.pptx", FileFormat.Pptx2010);

步驟二:取得第一張投影片上的表格         

##

Presentation ppt = new Presentation();
   ppt.LoadFromFile(@"C:\Users\Administrator\Desktop\创建表格.pptx");

三:刪除第四列及第四行                 

ITable table = null;
   foreach (IShape shape in ppt.Slides[0].Shapes)
   {
    if (shape is ITable)
    {
     table = (ITable)shape;

步驟四:保存文件  #  


3.刪除表格


步驟一:初始化一個Presentation實例並載入一個PowerPoint文件          

##

 table.ColumnsList.RemoveAt(3, false;
     table.TableRows.RemoveAt(4, false;
步驟二:初始化一個List對象,元素類型為IShape         

 ppt.SaveToFile("删除行与列.pptx", FileFormat.Pptx2010);
步驟三:取得第一張投影片上所有的表格圖形並新增至List          

Presentation ppt = new Presentation();
   ppt.LoadFromFile(@"C:\Users\Administrator\Desktop\创建表格.pptx");

步驟四:移除第一個表格圖形       
#

List<IShape> tableShapes = new List<IShape>();

步驟四:從投影片刪除第一個表格圖形       #  #步驟五:保存文件          


#

 foreach (IShape shape in ppt.Slides[0].Shapes)
   {
    if (shape is ITable)
    {
     tableShapes.Add(shape);
    }
   }




#################################################################################################

以上是C#使用Free Spire.Presentation實作對PPT插入與編輯以及刪除表格的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn