手抄报 安全手抄报 手抄报内容 手抄报图片 英语手抄报 清明节手抄报 节约用水手抄报

C# 添加 Word 超链接

时间:2024-10-14 20:07:42

1、下载安装该类库后,注意添加引用Spire.Doc.dll。dll文件可在安装路径下的Bin文件夹中获取。

2、添加文本超链接【C#】//创建一个Document实例并藜局腑载添加sectionDocument doc = new Document();Section s髫潋啜缅ection = doc.AddSection();//添加指向网址的超链接Paragraph para = section.AddParagraph();Paragraph para1 = section.AddParagraph();para1.AppendHyperlink("www.e-iceblue.com", "www.e-iceblue.com",HyperlinkType.WebLink);//添加指向邮件地址的超链接Paragraph para2 = section.AddParagraph();para2.AppendHyperlink("mailto:support @ e-iceblue.com", "support @ e-iceblue.com",HyperlinkType.EMailLink);//添加指向外部文件的超链接Paragraph para3 = section.AddParagraph();string filePath = @"C:\Users\Administrator\Desktop\月销售统计表.xls";para3.AppendHyperlink(filePath, "点击此处打开另一个文档",HyperlinkType.FileLink);//设置段落之间的间距para1.Format.AfterSpacing = 15f;para2.Format.AfterSpacing = 15f;//保存文档doc.SaveToFile("文本超链接.docx", FileFormat.Docx2013);调试代码并运行后,生成文档,如图所示:

C# 添加 Word 超链接

3、添加图片超链接【C#】//创建一个Document实例并添加sectionDocument doc = new Document();Section section = doc.AddSection();//添加段落Paragraph para = section.AddParagraph();//添加图片到段落并插入网站链接Image image = Image.FromFile(@"C:\Users\Administrator\Desktop\logo.jpg");Spire.Doc.Fields.DocPicture picture = para.AppendPicture(image);para.AppendHyperlink("www.e-iceblue.com", picture, HyperlinkType.WebLink);//保存文档doc.SaveToFile("图片超链接.docx", FileFormat.Docx2013);调试代码并运行后,生成文档如下图:

C# 添加 Word 超链接

4、格式化文本超链接默认状态下,超文本链接通常显示为蓝色带下划线。为了让超链接更醒目,我们也可以更改超链接的显示形式,例如去掉下划线、改变文本颜色、设置字体大小等。【C#】//埒摆缥膂创建一个Document实例并添加sectionDocument doc = new Document();Section section = doc.AddSection();//添加段落Paragraph para = section.AddParagraph();//添加超链接到段落并返回到一个TextRange对象TextRange txtRange = para.AppendHyperlink("www.e-iceblue.com", "WWW.E-ICEBLUE.COM", HyperlinkType.WebLink);//在TextRange中设置字体名字、大小、颜色、样式txtRange.CharacterFormat.FontName = "黑体";txtRange.CharacterFormat.TextColor = Color.Red;txtRange.CharacterFormat.FontSize = 15;txtRange.CharacterFormat.Bold = true;txtRange.CharacterFormat.UnderlineStyle = UnderlineStyle.None;//保存文档doc.SaveToFile("格式化超链接.docx", FileFormat.Docx2013);调试代码并运行后,生成文档如下图:

C# 添加 Word 超链接
© 手抄报圈