翻譯|使用教程|編輯:胡濤|2022-07-01 14:07:11.917|閱讀 157 次
概述:本指南中的解決方案介紹了如何在 C# 和 VB.NET 中插入和格式化 Word 頁面邊框。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Word 頁面邊框是頁面背景的一部分,用于美化文檔外觀。本指南中的解決方案介紹了如何在 C# 和 VB.NET 中插入和格式化 Word 頁面邊框。
通過對word文檔中的單詞或段落進行陰影處理,我們可以強調信息并輕松吸引他人的注意力。本文將向您展示如何在的幫助下在 C# 中設置段落底紋。
首先,下載 Spire.Doc并安裝在您的系統上。Spire.Doc 安裝干凈、專業,并包含在 MSI 安裝程序中。
然后,通過以下路徑在下載的 Bin 文件夾中添加 Spire.Doc.dll 作為參考:“..\Spire.Doc\Bin\NET4.0\ Spire.Doc.dll”。
現在介紹如何設置文本或段落的背景顏色的步驟。
第 1 步:創建一個新的 word 文檔并從文件中加載。
[C#]
Document document = new Document(); document.LoadFromFile(@"..\..\Sample.docx");
第 2 步:獲取一個段落。
[C#]
Paragraph paragaph = document.Sections[0].Paragraphs[0];
第 3 步:為段落或選定的單詞添加陰影。
[C#]
//Set background color for the paragraph paragaph.Format.BackColor = Color.Yellow; //Set background color for the selected text of paragraph paragaph = document.Sections[0].Paragraphs[1]; TextSelection selection= paragaph.Find("Blues",true,false); TextRange range = selection.GetAsOneRange(); range.CharacterFormat.TextBackgroundColor = Color.Yellow; Paragraph paragaph = document.Sections[0].Paragraphs[0];
第 4 步:將文檔保存到文件中。
[C#]
document.SaveToFile("sample.docx",FileFormat.Docx);
效果截圖:
完整代碼:
[C#]
using Spire.Doc; using Spire.Doc.Documents; using Spire.Doc.Fields; namespace SetWordParagh { class Program { static void Main(string[] args) { Document document = new Document(); document.LoadFromFile(@"..\..\Sample.docx"); Paragraph paragaph = document.Sections[0].Paragraphs[0]; //Set background color for the paragraph paragaph.Format.BackColor = Color.Yellow; //Set background color for the selected text of paragraph paragaph = document.Sections[0].Paragraphs[1]; TextSelection selection= paragaph.Find("Blues",true,false); TextRange range = selection.GetAsOneRange(); range.CharacterFormat.TextBackgroundColor = Color.Yellow; document.SaveToFile("sample.docx",FileFormat.Docx); } } }
歡迎下載|體驗更多E-iceblue產品
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn