Word控件Spire.Doc 【超链接】教程(5):使用 C# 更改颜色或从 Word 中的超链接中删除下划线

本文将介绍如何在 C# 中使用 Spire.Doc 去除下划线或更改超链接的颜色,欢迎查阅

默认情况下,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);

输出

Word控件Spire.Doc 【超链接】教程(5):使用 C# 更改颜色或从 Word 中的超链接中删除下划线

完整代码

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进行处理,非常感谢!

上一篇 2022年10月15日
下一篇 2022年10月15日

相关推荐

发表回复

登录后才能评论