翻譯|使用教程|編輯:胡濤|2023-02-14 09:18:40.127|閱讀 168 次
概述:本文將演示如何在 C# 中對(duì)齊表格,歡迎查閱
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Spire.Doc for .NET是一款專門對(duì) Word 文檔進(jìn)行操作的 .NET 類庫(kù)。在于幫助開(kāi)發(fā)人員無(wú)需安裝 Microsoft Word情況下,輕松快捷高效地創(chuàng)建、編輯、轉(zhuǎn)換和打印 Microsoft Word 文檔。擁有近10年專業(yè)開(kāi)發(fā)經(jīng)驗(yàn)Spire系列辦公文檔開(kāi)發(fā)工具,專注于創(chuàng)建、編輯、轉(zhuǎn)換和打印Word/PDF/Excel等格式文件處理,小巧便捷。
E-iceblue 功能類庫(kù)Spire 系列文檔處理組件均由中國(guó)本土團(tuán)隊(duì)研發(fā),不依賴第三方軟件,不受其他國(guó)家的技術(shù)或法律法規(guī)限制,同時(shí)適配國(guó)產(chǎn)操作系統(tǒng)如中科方德、中標(biāo)麒麟等,兼容國(guó)產(chǎn)文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
word表格通常有三種對(duì)齊方式:左對(duì)齊、居中和右對(duì)齊。在 Microsoft Word 中,我們可以進(jìn)入表格屬性來(lái)設(shè)置整個(gè)表格的對(duì)齊方式。Spire.Doc 還提供了一個(gè)屬性 table.TableFormat.HorizontalAlignment 使開(kāi)發(fā)者可以在 C# 中輕松設(shè)置表格對(duì)齊方式。本文將演示如何在 C# 中對(duì)齊表格。
首先,查看Microsoft word如何對(duì)齊表格:
下面來(lái)看Spire.Doc如何對(duì)齊表格的代碼片段。
第 1 步:創(chuàng)建一個(gè) word 文檔并從文件加載。
Document doc = new Document(); doc.LoadFromFile("sample.docx");
第 2 步:從word文檔中獲取第一節(jié)和兩個(gè)表格。
Section section = doc.Sections[0]; Table table = section.Tables[0] as Table; Table table1 = section.Tables[1] as Table;
第 3 步:為每個(gè)表格設(shè)置不同的對(duì)齊屬性。
table.TableFormat.HorizontalAlignment = RowAlignment.Right; table.TableFormat.LeftIndent = 34; table1.TableFormat.HorizontalAlignment = RowAlignment.Left; table1.TableFormat.LeftIndent = 34;
第 4 步:將文檔保存到文件:
doc.SaveToFile("result.docx", FileFormat.Docx);
對(duì)齊表格格式后的有效截圖:
完整代碼:
using Spire.Doc; using Spire.Doc.Documents; namespace AlignTable { class Program { static void Main(string[] args) { Document doc = new Document(); doc.LoadFromFile("sample.docx"); Section section = doc.Sections[0]; Table table = section.Tables[0] as Table; Table table1 = section.Tables[1] as Table; table.TableFormat.HorizontalAlignment = RowAlignment.Right; table.TableFormat.LeftIndent = 34; table1.TableFormat.HorizontalAlignment = RowAlignment.Left; table1.TableFormat.LeftIndent = 34; doc.SaveToFile("result.docx", FileFormat.Docx); } } }
以上便是如何在 C# 中對(duì)齊表格,如果您有其他問(wèn)題也可以繼續(xù)瀏覽本系列文章,獲取相關(guān)教程,你還可以給我留言或者加入我們的官方技術(shù)交流群。
歡迎下載|體驗(yàn)更多E-iceblue產(chǎn)品
獲取更多信息請(qǐng)咨詢 ;技術(shù)交流Q群(767755948)
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn