PPT控件Spire.Presentation 教程:在幻灯片表格中为文本设置水平对齐

首先,检查默认的对齐文档(左)。 然后,将对表上的不同行应用不同的对齐样式。

Step 1:创建演示文稿并从文件加载示例文档。

Presentation presentation = new Presentation();presentation.LoadFromFile("Sample.pptx",FileFormat.Pptx2010);

Step 2:从示例文档获取表。

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

Step 3:水平对齐文字。

for (int i = 0; i < table.ColumnsList.Count; i++){    table[i, 0].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Right;    table[i, 1].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Center;    table[i, 2].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Left;    table[i, 3].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.None;    table[i, 4].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Justify;}

Step 4:将文档保存到文件。

presentation.SaveToFile("tableresult.pptx", FileFormat.Pptx2010);

效果截图:

图片1

完整代码:

static void Main(string[] args){        Presentation presentation = new Presentation();        presentation.LoadFromFile("Sample.pptx",FileFormat.Pptx2010);        ITable table = null;        foreach (IShape shape in presentation.Slides[0].Shapes)        {            if (shape is ITable)            {                table = (ITable)shape;                for (int i = 0; i < table.ColumnsList.Count; i++)                {                    table[i, 0].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Right;                    table[i, 1].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Center;                    table[i, 2].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Left;                    table[i, 3].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.None;                    table[i, 4].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Justify;                }            }        }        presentation.SaveToFile("tableresult.pptx", FileFormat.Pptx2010);    }

控件

标签:文档管理PPT文档处理

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2017年7月1日
下一篇 2017年7月1日

相关推荐

发表回复

登录后才能评论