C#使用Free Spire.Presentation实现对PPT插入与编辑以及删除表格

黄舟
Release: 2017-10-01 07:24:57
Original
3005 people have browsed it

小编发现使用.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;
Copy after login

步骤二:初始化一个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);
Copy after login

步骤三:为表格设置内置格式


 table.StylePreset = TableStylePreset.LightStyle1Accent2;
Copy after login

步骤四:声明并初始化一个String[,]数组


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

步骤六:保存文档


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

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

2.删除表格行与列

步骤一:初始化一个Presentation实例并加载一个PowerPoint文档


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

步骤二:获取第一张幻灯片上的表格


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

步骤三:删除第四列及第四行


 table.ColumnsList.RemoveAt(3, false;
     table.TableRows.RemoveAt(4, false;
Copy after login

步骤四:保存文档


 ppt.SaveToFile("删除行与列.pptx", FileFormat.Pptx2010);
Copy after login

3.删除表格

步骤一:初始化一个Presentation实例并加载一个PowerPoint文档


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

步骤二:初始化一个List对象,元素类型为IShape


List tableShapes = new List();
Copy after login

步骤三:获取第一张幻灯片上所有的表格图形并添加到List


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

步骤四:从幻灯片删除第一个表格图形


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

步骤五:保存文档


ppt.SaveToFile("删除表格.pptx", FileFormat.Pptx2010);
Copy after login

总结

The above is the detailed content of C#使用Free Spire.Presentation实现对PPT插入与编辑以及删除表格. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Latest Issues
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!