代码片段:
第一步:创建一个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产品
获取更多信息请咨询在线客服 ;
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!