本文将重点介绍了如何设置C#中演示幻灯片表格上文本的水平对齐方式。 对于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);
效果截图:
完整代码:
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); }