翻譯|使用教程|編輯:胡濤|2022-12-27 10:00:58.383|閱讀 172 次
概述:本指南介紹如何使用Spire.Doc在 Word 中使用 C#/VB.NET 設置表格樣式,歡迎查閱!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Spire.Doc for .NET是一款專門對 Word 文檔進行操作的 .NET 類庫。在于幫助開發人員無需安裝 Microsoft Word情況下,輕松快捷高效地創建、編輯、轉換和打印 Microsoft Word 文檔。擁有近10年專業開發經驗Spire系列辦公文檔開發工具,專注于創建、編輯、轉換和打印Word/PDF/Excel等格式文件處理,小巧便捷。
Microsoft Word 中的表格用于呈現有助于解釋特定段落內容的數據信息。為了有更好的外觀,人們可以設置Word表格樣式。本指南介紹如何使用Spire.Doc在 Word 中使用 C#/VB.NET 設置表格樣式。
同時下載 Spire.Doc(或Spire.Office)和 .NET Framework 2.0(或以上)。確保 Spire.Doc(或 Spire.Office)在系統上正確安裝后,請按照以下步驟設置 Word 表格樣式
在本例中,準備了一個帶表格的 Word 文檔。這是來自 Office.com 的學生成績單模板。
[C#]
Document document = new Document(); document.LoadFromFile(@"E:\work\Documents\Student Transcript.docx");
[VB.NET]
Dim document As New Document() document.LoadFromFile("E:\work\Documents\Student Transcript.docx")
因為table1類型不同于document.Sections[0].Tables[1]類型,所以使用(Table)強制轉換。
[C#]
Table table1 = (Table)document.Sections[0].Tables[1];
[VB.NET]
Dim table1 As Table = CType(document.Sections(0).Tables(1), Table)
[C#]
table1.Rows[0].Height = 25;
[VB.NET]
table1.Rows(0).Height = 25
為了有區別。像以前一樣將第一個單元格保留在第一行,并為第二個單元格設置樣式。首先,為第二個單元格設置對齊方式和背景顏色。其次,聲明一個段落樣式,包括字體大小,顏色,并在單元格中應用這個樣式。
[C#]
table1.Rows[0].Cells[1].CellFormat.VerticalAlignment = VerticalAlignment.Middle; table1.Rows[0].Cells[1].CellFormat.BackColor = Color.LimeGreen; ParagraphStyle style = new ParagraphStyle(document); style.Name = "TableStyle"; style.CharacterFormat.FontSize = 14; style.CharacterFormat.TextColor = Color.GhostWhite; document.Styles.Add(style); table1.Rows[0].Cells[1].Paragraphs[0].ApplyStyle(style.Name);
[VB.NET]
table1.Rows(0).Cells(1).CellFormat.VerticalAlignment = VerticalAlignment.Middle table1.Rows(0).Cells(1).CellFormat.BackColor = Color.LimeGreen Dim style As New ParagraphStyle(document) style.Name = "TableStyle" style.CharacterFormat.FontSize = 14 style.CharacterFormat.TextColor = Color.GhostWhite document.Styles.Add(style) table1.Rows(0).Cells(1).Paragraphs(0).ApplyStyle(style.Name)
[C#]
document.SaveToFile("WordTable.docx", FileFormat.Docx); System.Diagnostics.Process.Start("WordTable.docx");
[VB.NET]
document.SaveToFile("WordTable.docx", FileFormat.Docx) System.Diagnostics.Process.Start("WordTable.docx")
有效截圖:
以上便如何在C#、VB.NET中設置Word表格樣式,如果您有其他問題也可以繼續瀏覽本系列文章,獲取相關教程,你還可以給我留言或者加入我們的官方技術交流群。
歡迎下載|體驗更多E-iceblue產品
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn