Word控件Spire.Doc 【超链接】教程(2):在 Silverlight 中插入 Word 超链接

本文将介绍如何在 Silverlight 中插入 Word 超链接,欢迎查阅~

Word超链接可以引导用户获取内容的其他相关信息。它可以是电子邮件地址、网站链接甚至其他文件。插入超链接时,用户可以添加指定文本或直接输入链接地址。

Silverlight 的Spire.Doc 是使用 Silverlight操作 Word 文档的强大组件,使用户能够使用 Silverlight 在 Word 中插入超链接。本指南将展示在 Silverlight 中实现插入单词超链接的方法。用户可以直接调用Spire.Doc为Silverlight提供的paragraph.AppendHyperlink(link string, text string, hyperlink type)方法在Word中插入超链接。

下载 Silverlight 的 Spire.Doc。创建 Silverlight 应用程序。在 MainPage.xaml 中添加一个按钮,然后将其加倍以使用以下代码插入超链接。

以下屏幕截图演示了在 Silverlight 中插入 Word 的超链接后的结果。超链接位于图片底部。

插入 Word 超链接

示例代码:

【C#】

using System;using System.Windows;using System.Windows.Controls;using System.IO;using System.Reflection;using Spire.Doc;using Spire.Doc.Documents;namespace InsertHyperlink{public partial class MainPage : UserControl{public MainPage(){InitializeComponent();}private void button1_Click(object sender, RoutedEventArgs e){//Declare SaveFileDialogSaveFileDialog save = new SaveFileDialog();save.Filter = "Word Document(*.docx)|*.docx";//Load DocumentDocument document = new Document();Assembly assembly = this.GetType().Assembly;foreach (String name in assembly.GetManifestResourceNames()){if (name.EndsWith("Spire.Doc for Silverlight.docx")){using (Stream docStream = assembly.GetManifestResourceStream(name)){document = new Document(docStream, FileFormat.Docx);}}}//Add HyperlinkSection section = document.Sections[0];Paragraph LinkPara = section.AddParagraph();LinkPara.AppendHyperlink("http://www.e-iceblue.com/Introduce/word-for-silverlight-introduce.html", "Learn More about Spire.Doc for Siverlight", HyperlinkType.WebLink);//Set Paragrah StyleParagraphStyle style = new ParagraphStyle(document);style.Name = "LinkStyle";style.CharacterFormat.FontName = "Britannic Bold";style.CharacterFormat.FontSize = 13;style.ParagraphFormat.LineSpacingRule = LineSpacingRule.Multiple;style.ParagraphFormat.LineSpacing = 15F;document.Styles.Add(style);LinkPara.ApplyStyle(style.Name);//Save Documentboolresult = save.ShowDialog();if (result.HasValue && result.Value){using (Stream stream = save.OpenFile()){document.SaveToStream(stream, FileFormat.Docx);}}}}}

[VB.NET]

Imports System.IOImports System.ReflectionImports System.DrawingImports Spire.DocImports Spire.Doc.DocumentsPartial Public Class MainPageInherits UserControlPublic Sub New()InitializeComponent()End SubPrivate Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click'Declare SaveFileDialogDim save As New SaveFileDialog()save.Filter = "Word Document(*.docx)|*.docx"'Load DocumentDim document As New Document()Dim [assembly] As System.Reflection.Assembly = Me.GetType().AssemblyFor Each name As String In [assembly].GetManifestResourceNames()If name.EndsWith("Spire.Doc for Silverlight.docx") ThenUsing docStream As Stream = [assembly].GetManifestResourceStream(name)document = New Document(docStream, FileFormat.Docx)End UsingEnd IfNext name'Add HyperlinkDim section As Section = document.Sections(0)Dim LinkPara As Paragraph = section.AddParagraph()LinkPara.AppendHyperlink("http://www.e-iceblue.com/Introduce/word-for-silverlight-introduce.html", "Learn More about Spire.Doc for Siverlight", HyperlinkType.WebLink)'Set Paragrah StyleDim style As New ParagraphStyle(document)style.Name = "LinkStyle"style.CharacterFormat.FontName = "Britannic Bold"style.CharacterFormat.FontSize = 13style.ParagraphFormat.LineSpacingRule = LineSpacingRule.Multiplestyle.ParagraphFormat.LineSpacing = 15.0Fdocument.Styles.Add(style)LinkPara.ApplyStyle(style.Name)'Save DocumentDim resultAs Boolean = save.ShowDialog()If result.HasValue AndAlso result.Value ThenUsing stream As Stream = save.OpenFile()document.SaveToStream(stream, FileFormat.Docx)End UsingEnd IfEnd SubEnd Class

以上便是如何在C#中旋转word文档上的形状,如果您有其他问题也可以继续浏览本系列文章,获取相关教程,你还可以给我留言或者加入我们的官方技术交流群。


欢迎下载|体验更多E-iceblue产品

获取更多信息请咨询在线客服  


标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

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

相关推荐

发表回复

登录后才能评论