Word控件Spire.Doc 【超链接】教程(2):在 Silverlight 中插入 Word 超链接
教程 控件 插入 word doc SPIRE 超链接 Silverlight
2023-09-11 14:14:49 时间
Spire.Doc for .NET是一款专门对 Word 文档进行操作的 .NET 类库。在于帮助开发人员无需安装 Microsoft Word情况下,轻松快捷高效地创建、编辑、转换和打印 Microsoft Word 文档。拥有近10年专业开发经验Spire系列办公文档开发工具,专注于创建、编辑、转换和打印Word/PDF/Excel等格式文件处理,小巧便捷。
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 的超链接后的结果。超链接位于图片底部。
示例代码:
【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 SaveFileDialog SaveFileDialog save = new SaveFileDialog(); save.Filter = "Word Document(*.docx)|*.docx"; //Load Document Document 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 Hyperlink Section 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 Style ParagraphStyle 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 Document bool? result = save.ShowDialog(); if (result.HasValue && result.Value) { using (Stream stream = save.OpenFile()) { document.SaveToStream(stream, FileFormat.Docx); } } } } }
[VB.NET]
Imports System.IO Imports System.Reflection Imports System.Drawing Imports Spire.Doc Imports Spire.Doc.Documents Partial Public Class MainPage Inherits UserControl Public Sub New() InitializeComponent() End Sub Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click 'Declare SaveFileDialog Dim save As New SaveFileDialog() save.Filter = "Word Document(*.docx)|*.docx" 'Load Document Dim document As New Document() Dim [assembly] As System.Reflection.Assembly = Me.GetType().Assembly For Each name As String In [assembly].GetManifestResourceNames() If name.EndsWith("Spire.Doc for Silverlight.docx") Then Using docStream As Stream = [assembly].GetManifestResourceStream(name) document = New Document(docStream, FileFormat.Docx) End Using End If Next name 'Add Hyperlink Dim 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 Style Dim style As New ParagraphStyle(document) style.Name = "LinkStyle" style.CharacterFormat.FontName = "Britannic Bold" style.CharacterFormat.FontSize = 13 style.ParagraphFormat.LineSpacingRule = LineSpacingRule.Multiple style.ParagraphFormat.LineSpacing = 15.0F document.Styles.Add(style) LinkPara.ApplyStyle(style.Name) 'Save Document Dim result? As Boolean = save.ShowDialog() If result.HasValue AndAlso result.Value Then Using stream As Stream = save.OpenFile() document.SaveToStream(stream, FileFormat.Docx) End Using End If End Sub End Class
以上便是如何在C#中旋转word文档上的形状,如果您有其他问题也可以继续浏览本系列文章,获取相关教程,你还可以给我留言或者加入我们的官方技术交流群。
相关文章
- 教程-MessageBox 使用方法
- Spring Boot 2.0 的快速入门(图文教程)
- 【python】廖雪峰python教程学习--基础
- gradle配置及使用教程、groovy入门示例
- 【第3版emWin教程】第50章 emWin6.x的AppWizard使用控件经典回调方式
- 【STM32F407的DSP教程】第37章 STM32F407的FIR低通滤波器实现(支持逐个数据的实时滤波)
- SAP UI5 应用开发教程之九十四 - 基于 JSONModel 数据模型的 SAP UI5 列表控件分页显示数据的完整解决方案试读版
- SAP UI5 应用开发教程之六十二 - 基于 OData V4 的 SAP UI5 表格控件使用方法介绍试读版
- SAP UI5 应用开发教程之五十六 - SAP UI5 树控件(tree)的开发试读版
- SAP UI5 应用开发教程之五十二 - 如何使用 SAP UI5 的标准控件结合 Cordova 插件调用手机摄像头进行条形码扫描试读版
- SAP UI5 应用开发教程之四十四 - Label 和 Input 控件文本没有水平对齐的原因分析和解决方案
- SAP UI5 应用开发教程之三十二 - 如何创建一个自定义 SAP UI5 控件试读版
- SAP UI5 初学者教程之二十三 - 列表控件的排序 Sort 和分组 Group 试读版
- SAP UI5 应用开发教程之七十 - 如何使用按钮控件触发页面路由跳转试读版
- SAP UI5 应用开发教程之六十六 - 基于 OData V4 的 SAP UI5 表格控件如何实现删除功能试读版
- SAP UI5 应用开发教程之六十 - SAP UI5 地图控件的一些高级用法试读版
- SAP UI5 应用开发教程之三十二 - 如何创建一个自定义 SAP UI5 控件试读版
- Unity跨平台UI解决方案:可能是最全的FairyGUI系列教程.Part1
- android自己定义控件系列教程----视图
- 【大数据 OLAP】Apache Kudu 极简教程
- 这个教程,真的让我学会了正则表达式
- 华为云服务器80端口放通教程(安全组配置规则)
- Python基于改进Resnet和Vgg新冠肺炎分类[源码&部署教程]