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

更多Spire文档管理控件体验
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!