翻譯|使用教程|編輯:胡濤|2022-11-18 11:37:13.413|閱讀 220 次
概述:本文將介紹如何在 C# 中使用 Spire.Doc 去除下劃線或更改超鏈接的顏色,歡迎查閱
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Spire.Doc for .NET是一款專門對 Word 文檔進行操作的 .NET 類庫。在于幫助開發人員無需安裝 Microsoft Word情況下,輕松快捷高效地創建、編輯、轉換和打印 Microsoft Word 文檔。擁有近10年專業開發經驗Spire系列辦公文檔開發工具,專注于創建、編輯、轉換和打印Word/PDF/Excel等格式文件處理,小巧便捷。
默認情況下,Word 中的超鏈接顯示為藍色并帶有下劃線。在某些情況下,用戶可能希望修改超鏈接樣式以使整個文檔看起來更好看。本文將介紹如何在 C# 中使用 Spire.Doc 去除下劃線或更改超鏈接的顏色。
代碼片段:
第一步:創建一個Document類的新對象,添加一個section。
Document document = new Document(); Section section = document.AddSection();
第 2 步:添加一個段落并將超鏈接附加到該段落。為了格式化超鏈接,我們在 TextRange 中返回超鏈接的值。
Paragraph para= section.AddParagraph(); TextRange txtRange = para1.AppendHyperlink("www.e-iceblue.com", "www.e-iceblue.com", HyperlinkType.WebLink);
第 3 步:使用指定的字體名稱、字體大小、顏色和下劃線樣式來格式化超鏈接。
txtRange.CharacterFormat.FontName = "Times New Roman"; txtRange.CharacterFormat.FontSize = 12; txtRange.CharacterFormat.TextColor = System.Drawing.Color.Red; txtRange.CharacterFormat.UnderlineStyle = UnderlineStyle.None;
第 4 步:保存文件。
document.SaveToFile("result.docx", FileFormat.Docx2013);
輸出:
完整代碼:
using Spire.Doc; using Spire.Doc.Documents; using Spire.Doc.Fields; namespace FormatHyperlink { class Program { static void Main(string[] args) { Document document = new Document(); Section section = document.AddSection(); Paragraph para1= section.AddParagraph(); para1.AppendText("Regular Link: "); TextRange txtRange1 = para1.AppendHyperlink("www.e-iceblue.com", "www.e-iceblue.com", HyperlinkType.WebLink); txtRange1.CharacterFormat.FontName = "Times New Roman"; txtRange1.CharacterFormat.FontSize = 12; Paragraph blankPara1 = section.AddParagraph(); Paragraph para2 = section.AddParagraph(); para2.AppendText("Change Color: "); TextRange txtRange2 = para2.AppendHyperlink("www.e-iceblue.com", "www.e-iceblue.com", HyperlinkType.WebLink); txtRange2.CharacterFormat.FontName = "Times New Roman"; txtRange2.CharacterFormat.FontSize = 12; txtRange2.CharacterFormat.TextColor = System.Drawing.Color.Red; Paragraph blankPara2 = section.AddParagraph(); Paragraph para3 = section.AddParagraph(); para3.AppendText("Remove Underline: "); TextRange txtRange3 = para3.AppendHyperlink("www.e-iceblue.com", "www.e-iceblue.com", HyperlinkType.WebLink); txtRange3.CharacterFormat.FontName = "Times New Roman"; txtRange3.CharacterFormat.FontSize = 12; txtRange3.CharacterFormat.UnderlineStyle = UnderlineStyle.None; document.SaveToFile("result.docx", FileFormat.Docx2013); System.Diagnostics.Process.Start("result.docx"); } } }
以上便是如何使用 C# 更改顏色或從 Word 中的超鏈接中刪除下劃線,如果您有其他問題也可以繼續瀏覽本系列文章,獲取相關教程,你還可以給我留言或者加入我們的官方技術交流群。
歡迎下載|體驗更多E-iceblue產品
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn