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

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 的超链接后的结果。超链接位于图片底部。

Word控件Spire.Doc 【超链接】教程(2):在 Silverlight 中插入 Word 超链接_第1张图片

示例代码:

【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文档上的形状,如果您有其他问题也可以继续浏览本系列文章,获取相关教程,你还可以给我留言或者加入我们的官方技术交流群。 

你可能感兴趣的:(Spire.Doc,for.net,教程(完),word,python,c#,pdf,spire.doc)