翻譯|使用教程|編輯:胡濤|2022-02-22 13:53:16.590|閱讀 346 次
概述:為了便于使用者體驗,在本文檔中,我們將介紹使用 Visual Studio 完成一個關于 Spire.Doc 的簡單演示!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
在本文檔中,我們將快速幫助您使用 Visual Studio 完成一個關于 Spire.Doc 的簡單演示。在開始之前,請確保您的計算機上安裝了 Spire.Doc for .NET 和 Visual Studio(2008 或更高版本)。
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 Files\e-iceblue\Spire.Doc”,雙擊文件夾Bin。
選擇程序集 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.Doc Imports Spire.Doc.Documents
6.在方法btnRun_Click中添加如下代碼:
[C#]
//Create word document Document document = new Document(); //Create a new paragraph Paragraph paragraph = document.AddSection().AddParagraph(); //Append Text paragraph.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 document Dim document_Renamed As New Document() 'Create a new paragraph Dim paragraph_Renamed As Paragraph = document_Renamed.AddSection().AddParagraph() 'Append Text paragraph_Renamed.AppendText("Hello World!") 'Save doc file. document_Renamed.SaveToFile("Sample.doc", FileFormat.Doc) 'Launching the MS Word file. Try System.Diagnostics.Process.Start("Sample.doc") Catch End Try
7. 在 Solution Explorer ,右鍵單擊項目HelloWorld并單擊Debug,然后單擊 Start new instance,您將看到打開的窗口 Form1,單擊“Run ”按鈕,將創建、編輯并打開一個 Word 文檔,字符串“Hello, World”將填充在第 1 頁的第一行。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn