原創(chuàng)|使用教程|編輯:王香|2017-08-01 16:25:49.000|閱讀 623 次
概述:Spire.Presentation是一個(gè)專業(yè)的 PowerPoint控件,用于幫助開(kāi)發(fā)人員高效地創(chuàng)建、讀取、編輯、轉(zhuǎn)換和打印任PPT文檔,本文介紹了如何在演示幻燈片的表格中為文本設(shè)置水平對(duì)齊方式。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷售中 >>
相關(guān)鏈接:
本文將重點(diǎn)介紹了如何設(shè)置C#中演示幻燈片表格上文本的水平對(duì)齊方式。 對(duì)于Spire.Presentation的文本對(duì)齊方式有五個(gè)選項(xiàng):左,右,中心,對(duì)齊和無(wú)。
首先,檢查默認(rèn)的對(duì)齊文檔(左)。 然后,將對(duì)表上的不同行應(yīng)用不同的對(duì)齊樣式。
Step 1:創(chuàng)建演示文稿并從文件加載示例文檔。
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:水平對(duì)齊文字。
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); }
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn