现代学习和办公当中,经常会接触到对表格的运用,像各种单据、报表、账户等等。在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);
步骤三:为表格设置内置格式
table.stylepreset = tablestylepreset.lightstyle1accent2;
步骤四:声明并初始化一个string[,]数组
string[,] data = new string[,] { {"排名","姓名", "销售额","回款额","工号"}, {"1","李彪","18270","18270","0011"}, {"2","李娜","18105","18105","0025"}, {"3","张丽","17987","17987","0008"}, {"4","黄艳","17790","17790","0017"}, };
步骤六:保存文档
ppt.savetofile("创建表格.pptx", fileformat.pptx2010);
完成操作后得到以下ppt文档效果
2.删除表格行与列
步骤一:初始化一个presentation实例并加载一个powerpoint文档
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;
步骤三:删除第四列及第四行
table.columnslist.removeat(3, false; table.tablerows.removeat(4, false;
步骤四:保存文档
ppt.savetofile("删除行与列.pptx", fileformat.pptx2010);
3.删除表格
步骤一:初始化一个presentation实例并加载一个powerpoint文档
presentation ppt = new presentation(); ppt.loadfromfile(@"c:\users\administrator\desktop\创建表格.pptx");
步骤二:初始化一个list对象,元素类型为ishape
list<ishape> tableshapes = new list<ishape>();
步骤三:获取第一张幻灯片上所有的表格图形并添加到list
foreach (ishape shape in ppt.slides[0].shapes) { if (shape is itable) { tableshapes.add(shape); } }
步骤四:从幻灯片删除第一个表格图形
ppt.slides[0].shapes.remove(tableshapes[0]);
步骤五:保存文档
ppt.savetofile("删除表格.pptx", fileformat.pptx2010);
总结
以上所述是小编给大家介绍的c# 使用free spire.presentation 实现对ppt插入、编辑、删除表格,希望对大家有所帮助
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
网友评论