原創|使用教程|編輯:王香|2017-08-01 16:25:49.000|閱讀 623 次
概述:Spire.Presentation是一個專業的 PowerPoint控件,用于幫助開發人員高效地創建、讀取、編輯、轉換和打印任PPT文檔,本文介紹了如何在演示幻燈片的表格中為文本設置水平對齊方式。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
本文將重點介紹了如何設置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); }
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn