翻譯|使用教程|編輯:胡濤|2022-02-22 13:53:16.590|閱讀 365 次
概述:為了便于使用者體驗(yàn),在本文檔中,我們將介紹使用 Visual Studio 完成一個(gè)關(guān)于 Spire.Doc 的簡(jiǎn)單演示!
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
在本文檔中,我們將快速幫助您使用 Visual Studio 完成一個(gè)關(guān)于 Spire.Doc 的簡(jiǎn)單演示。在開始之前,請(qǐng)確保您的計(jì)算機(jī)上安裝了 Spire.Doc for .NET 和 Visual Studio(2008 或更高版本)。
1. 在 Visual Studio 中,依次單擊File、New、Project,如果要?jiǎng)?chuàng)建 C# 項(xiàng)目,請(qǐng)選擇Visual C#、Windows并選擇Windows Forms Application并將項(xiàng)目命名為HelloWorld,單擊OK。如果要?jiǎng)?chuàng)建Visual Basic項(xiàng)目,請(qǐng)選擇Visual Basic、Windows Forms Application并將項(xiàng)目命名為HelloWorld,單擊OK。
2. 在解決方案資源管理器中,右鍵單擊項(xiàng)目HelloWorld并單擊添加引用。在Browse選項(xiàng)卡中,找到您安裝 Spire.Doc for .NET 的文件夾,默認(rèn)為“C:\Program Files\e-iceblue\Spire.Doc”,雙擊文件夾Bin。
選擇程序集 Spire.Doc.dll 并單擊“OK”將其添加到項(xiàng)目中。
3. 在解決方案資源管理器中,雙擊文件 Form1.cs/Form1.vb 以打開表單設(shè)計(jì)視圖,在表單中添加一個(gè)按鈕,并將其名稱更改為“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 ,右鍵單擊項(xiàng)目HelloWorld并單擊Debug,然后單擊 Start new instance,您將看到打開的窗口 Form1,單擊“Run ”按鈕,將創(chuàng)建、編輯并打開一個(gè) Word 文檔,字符串“Hello, World”將填充在第 1 頁(yè)的第一行。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@ke049m.cn