翻譯|使用教程|編輯:胡濤|2022-03-08 13:16:24.830|閱讀 247 次
概述:
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
自 1990 年代以來,Microsoft 開始為其一系列專有的文字處理格式使用 .doc 擴展名。Doc 格式通常與 Microsoft Office 應用程序相關聯。但是在 Doc 文件中存儲文本并不總是很方便,因為它們與大多數第三方文本編輯器不兼容。為了使 Doc 信息更易于訪問,最好將其存儲為其他更常見的格式。用戶通常選擇 RTF 格式,因為它受到廣泛的應用程序的支持。
Spire.Doc for .NET 可以在您的系統上不安裝 Microsoft Office 的情況下將 Word 轉換為 RTF。使用 .NET Framework 2.0(或更高版本)下載Spire.Doc(或Spire.Office),然后按照以下簡單步驟將 Word 轉換為 RTF。
第 1 步:通過 Visual Studio 創建一個項目并添加 Spire.Doc DLL 作為參考。
第 2 步:加載我們需要轉換為 RTF 格式的本地 Word doc 文件。使用下面的代碼加載 Word 文件。
Document document = new Document(); document.LoadFromFile(@"D:\Sample.doc");
第 3 步:Spire.Doc 允許用戶將 Word doc 文件轉換為大多數流行的文件格式,包括 PDF、HTML、RTF、EPub、XML、Dot、Text 等。以下代碼可以幫助我們將 Word 轉換為 RTF。
document.SaveToFile("Sample.rtf", FileFormat.Rtf);
第 4 步:將下面的完整代碼復制到項目中,然后按 F5 啟動項目。
完整代碼:
[C#]
using Spire.Doc; using System; namespace DOCRTF { class Program { static void Main(string[] args) { } private void button1_Click(object sender, EventArgs e) { //Create word document Document document = new Document(); document.LoadFromFile(@"D:\Sample.doc"); //Save doc file. document.SaveToFile("Sample.rtf", FileFormat.Rtf); //Launching the MS Word file. WordDocViewer("Sample.rtf"); } private void WordDocViewer(string fileName) { try { System.Diagnostics.Process.Start(fileName); } catch { } } } }
[VB.NET]
Imports Spire.Doc Namespace DOCRTF Class Program Private Shared Sub Main(args As String()) End Sub Private Sub button1_Click(sender As Object, e As EventArgs) 'Create word document Dim document As New Document() document.LoadFromFile("D:\Sample.doc") 'Save doc file. document.SaveToFile("Sample.rtf", FileFormat.Rtf) 'Launching the MS Word file. WordDocViewer("Sample.rtf") End Sub Private Sub WordDocViewer(fileName As String) Try System.Diagnostics.Process.Start(fileName) Catch End Try End Sub End Class End Namespace
有效截圖:
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn