翻譯|使用教程|編輯:胡濤|2022-12-27 10:00:58.383|閱讀 172 次
概述:本指南介紹如何使用Spire.Doc在 Word 中使用 C#/VB.NET 設(shè)置表格樣式,歡迎查閱!
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Spire.Doc for .NET是一款專門對(duì) Word 文檔進(jìn)行操作的 .NET 類庫(kù)。在于幫助開發(fā)人員無(wú)需安裝 Microsoft Word情況下,輕松快捷高效地創(chuàng)建、編輯、轉(zhuǎn)換和打印 Microsoft Word 文檔。擁有近10年專業(yè)開發(fā)經(jīng)驗(yàn)Spire系列辦公文檔開發(fā)工具,專注于創(chuàng)建、編輯、轉(zhuǎn)換和打印Word/PDF/Excel等格式文件處理,小巧便捷。
Microsoft Word 中的表格用于呈現(xiàn)有助于解釋特定段落內(nèi)容的數(shù)據(jù)信息。為了有更好的外觀,人們可以設(shè)置Word表格樣式。本指南介紹如何使用Spire.Doc在 Word 中使用 C#/VB.NET 設(shè)置表格樣式。
同時(shí)下載 Spire.Doc(或Spire.Office)和 .NET Framework 2.0(或以上)。確保 Spire.Doc(或 Spire.Office)在系統(tǒng)上正確安裝后,請(qǐng)按照以下步驟設(shè)置 Word 表格樣式
在本例中,準(zhǔn)備了一個(gè)帶表格的 Word 文檔。這是來(lái)自 Office.com 的學(xué)生成績(jī)單模板。
[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")
因?yàn)閠able1類型不同于document.Sections[0].Tables[1]類型,所以使用(Table)強(qiáng)制轉(zhuǎn)換。
[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
為了有區(qū)別。像以前一樣將第一個(gè)單元格保留在第一行,并為第二個(gè)單元格設(shè)置樣式。首先,為第二個(gè)單元格設(shè)置對(duì)齊方式和背景顏色。其次,聲明一個(gè)段落樣式,包括字體大小,顏色,并在單元格中應(yīng)用這個(gè)樣式。
[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中設(shè)置Word表格樣式,如果您有其他問題也可以繼續(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