欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C# 使用Free Spire.Presentation 實(shí)現(xiàn)對(duì)PPT插入、編輯、刪除表格

 更新時(shí)間:2017年09月30日 10:32:30   作者:E-iceblue  
小編發(fā)現(xiàn)使用.NET組件——Free Spire.Presentation,在C#中添加該產(chǎn)品DLL文件,可以簡(jiǎn)單快速地實(shí)現(xiàn)對(duì)演示文稿的表格插入、編輯和刪除等操作,具體實(shí)現(xiàn)代碼大家參考下本文吧

現(xiàn)代學(xué)習(xí)和辦公當(dāng)中,經(jīng)常會(huì)接觸到對(duì)表格的運(yùn)用,像各種單據(jù)、報(bào)表、賬戶(hù)等等。在PPT演示文稿中同樣不可避免的應(yīng)用到各種數(shù)據(jù)表格。對(duì)于在PPT中插入表格,我發(fā)現(xiàn)了一個(gè)新方法,不過(guò)我用到了一款免費(fèi)的.NET組件——Free Spire.Presentation,在C#中添加該產(chǎn)品DLL文件,可以簡(jiǎn)單快速地實(shí)現(xiàn)對(duì)演示文稿的表格插入、編輯和刪除等操作。有需要的話(huà)可以在下面的網(wǎng)址下載:https://www.e-iceblue.cn/Downloads/Free-Spire-Presentation-NET.html

1.插入表格

步驟一:創(chuàng)建一個(gè)PowerPoint文檔

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

步驟二:初始化一個(gè)ITable實(shí)例,并指定位置、行數(shù)和列數(shù)、行高和列寬           

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);

步驟三:為表格設(shè)置內(nèi)置格式          

 table.StylePreset = TableStylePreset.LightStyle1Accent2;

步驟四:聲明并初始化一個(gè)String[,]數(shù)組       

 string[,] data = new string[,]
{
   {"排名","姓名", "銷(xiāo)售額","回款額","工號(hào)"},
   {"1","李彪","18270","18270","0011"},
   {"2","李娜","18105","18105","0025"},
   {"3","張麗","17987","17987","0008"},
   {"4","黃艷","17790","17790","0017"},
};

步驟六:保存文檔          

 ppt.SaveToFile("創(chuàng)建表格.pptx", FileFormat.Pptx2010);

完成操作后得到以下PPT文檔效果

2.刪除表格行與列

步驟一:初始化一個(gè)Presentation實(shí)例并加載一個(gè)PowerPoint文檔        

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

步驟二:獲取第一張幻燈片上的表格         

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

步驟三:刪除第四列及第四行                 

 table.ColumnsList.RemoveAt(3, false;
     table.TableRows.RemoveAt(4, false;

步驟四:保存文檔          

 ppt.SaveToFile("刪除行與列.pptx", FileFormat.Pptx2010);

3.刪除表格

步驟一:初始化一個(gè)Presentation實(shí)例并加載一個(gè)PowerPoint文檔          

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

步驟二:初始化一個(gè)List對(duì)象,元素類(lèi)型為IShape         

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

步驟三:獲取第一張幻燈片上所有的表格圖形并添加到List          

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

步驟四:從幻燈片刪除第一個(gè)表格圖形           

ppt.Slides[0].Shapes.Remove(tableShapes[0]);

步驟五:保存文檔          

ppt.SaveToFile("刪除表格.pptx", FileFormat.Pptx2010);

總結(jié)

以上所述是小編給大家介紹的C# 使用Free Spire.Presentation 實(shí)現(xiàn)對(duì)PPT插入、編輯、刪除表格,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論