删去表格

现代念书和办公当中,平常会接触到对表格的接纳,像种种单据、报表、账户等等。在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文书档案效果

爱博体育app 1

2.剔除表格行与列

步骤大器晚成:起始化三个Presentation实例并加载二个PowerPoint文书档案

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

手续二:获取第一张幻灯片上的表格

for (int i = 0; i < 5; i++)
{
    for (int j = 0; j < 5; j++)
    {
        table[j, i].TextFrame.Text = data[i, j];
        table[j, i].TextFrame.Paragraphs[0].TextRanges[0].LatinFont = new TextFont("Arial");
    }
}

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

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

手续四:保存文书档案

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

爱博体育app 2

爱博体育app,3.剔除表格

步骤朝气蓬勃:初阶化贰个Presentation实例并加载一个PowerPoint文书档案

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

步骤二:早先化五个List对象,成分类型为IShape

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

手续三:获取第一张幻灯片上装有的表格图形并增多到List

for (int i = 0; i < 5; i++)
{
    for (int j = 0; j < 5; j++)
    {
        table[j, i].TextFrame.Text = data[i, j];
        table[j, i].TextFrame.Paragraphs[0].TextRanges[0].LatinFont = new TextFont("Arial");
    }
}

手续四:从幻灯片删除第二个表格图形

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

手续五:保存文书档案

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

 

以上是本人使用Free
Spire.Presentation那款组件对PPT文书档案中表格的一些操作,希望能提供帮扶,谢谢阅读!

 

相关文章