Word格式处理控件Spire.Doc功能演示:在 .NET 应用程序中使用 Spire.Doc for.net

为了便于使用者体验,在本文档中,我们将介绍使用 Visual Studio 完成一个关于 Spire.Doc 的简单演示!

在本文档中,我们将快速帮助您使用 Visual Studio 完成一个关于 Spire.Doc 的简单演示。在开始之前,请确保您的计算机上安装了

1. 在 Visual Studio 中,依次单击File、New、Project,如果要创建 C# 项目,请选择Visual C#、Windows并选择Windows Forms Application并将项目命名为HelloWorld,单击OK。如果要创建Visual Basic项目,请选择Visual Basic、Windows Forms Application并将项目命名为HelloWorld,单击OK。  

2. 在解决方案资源管理器中,右键单击项目HelloWorld并单击添加引用。在Browse选项卡中,找到您安装 Spire.Doc for .NET 的文件夹,默认为“C:Program Filese-iceblueSpire.Doc”,双击文件夹Bin。

  • 是.NET 2.0,双击文件夹NET2.0
  • 是.NET 3.5,双击文件夹NET3.5
  • 是.NET 4.0,双击文件夹NET4.0

选择程序集 Spire.Doc.dll 并单击“OK”将其添加到项目中。

3. 在解决方案资源管理器中,双击文件 Form1.cs/Form1.vb 以打开表单设计视图,在表单中添加一个按钮,并将其名称更改为“btnRun”,将其文本更改为“Run ”。

4. 双击“Run ”按钮,您将看到代码视图:

[C#]  

private void btnRun_Click(object sender, EventArgs e)

[VB.NET] 

Private Sub btnRun_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRun.Click

5. 将以下代码添加到文件顶部:

[C#] 

using Spire.Doc;using Spire.Doc.Documents;

[VB.NET]  

Imports Spire.DocImports Spire.Doc.Documents

6.在方法btnRun_Click中添加如下代码:

[C#]  

//Create word documentDocument document = new Document();//Create a new paragraphParagraph paragraph = document.AddSection().AddParagraph();//Append Textparagraph.AppendText("Hello World!");//Save doc file.document.SaveToFile("Sample.doc", FileFormat.Doc);//Launching the MS Word file.try{System.Diagnostics.Process.Start("Sample.doc");}catch { }

[VB.NET]   

'Create word documentDim document_Renamed As New Document()'Create a new paragraphDim paragraph_Renamed As Paragraph = document_Renamed.AddSection().AddParagraph()'Append Textparagraph_Renamed.AppendText("Hello World!")'Save doc file.document_Renamed.SaveToFile("Sample.doc", FileFormat.Doc)'Launching the MS Word file.TrySystem.Diagnostics.Process.Start("Sample.doc")CatchEnd Try

7. 在 Solution Explorer ,右键单击项目HelloWorld并单击Debug,然后单击 Start new instance,您将看到打开的窗口 Form1,单击“Run ”按钮,将创建、编辑并打开一个 Word 文档,字符串“Hello, World”将填充在第 1 页的第一行。

在 .NET 应用程序中使用 Spire.Doc

更多Spire文档管理控件体验

标签:

来源:慧都

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

上一篇 2022年1月19日
下一篇 2022年1月19日

相关推荐

发表回复

登录后才能评论