文檔半島外圍網上直營>>E-iceblue中文文檔>>在 C# 中設置單詞段落底紋
                在 C# 中設置單詞段落底紋
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);
}
}
}                
            
 QQ交談
QQ交談 在線咨詢
在線咨詢 
                 
                
 渝公網安備
            50010702500608號
渝公網安備
            50010702500608號
             
            
 客服熱線
客服熱線