在Spire.Presentation的帮助下,我们可以轻松设置幻灯片中的表格边框类型和颜色。本文将重点介绍如何在C#设置PowerPoint中的表格边框类型和颜色。
首先,请查看Microsoft PowerPoint中的12种框线类型:
为PowerPoint文档中已有的表格设置边框类型和颜色:
//初始化一个Presentation实例并示例文档
Presentation presentation = new Presentation();
presentation.LoadFromFile("Sample.pptx");
//获取第一张幻灯片里的表格
ISlide slide = presentation.Slides[0];
ITable table = slide.Shapes[0] as ITable;
//设置边框类型为内部框线并将颜色设为蓝色
table.SetTableBorder(TableBorderType.Inside, 1, Color.Blue);
//保存文档
presentation.SaveToFile("Insideborder.pptx", FileFormat.Pptx2010);
效果图:
PowerPoint文档新建表格时设置边框类型和颜色:
//初始化一个Presentation实例
Presentation presentation = new Presentation();
//设置表格高度和宽度
double[] tableWidth = new double[] { 100, 100, 100, 100, 100 };
double[] tableHeight = new double[] { 20, 20 };
//遍历表格框线类型
foreach (TableBorderType item in Enum.GetValues(typeof(TableBorderType)))
//按设置好的高度和宽度插入一个表格
{
ITable itable = presentation.Slides.Append().Shapes.AppendTable(100, 100, tableWidth, tableHeight);
//添加文字到单元格
itable.TableRows[0][0].TextFrame.Text = "第一行";
itable.TableRows[1][0].TextFrame.Text = "第二行";
//设置表格框线类型,宽度和颜色
itable.SetTableBorder(item, 1.5, Color.Red);
}
//保存文档
presentation.SaveToFile("Addtablewithborder.pptx", FileFormat.Pptx2010);