翻譯|使用教程|編輯:胡濤|2022-03-08 13:16:24.830|閱讀 247 次
概述:
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
自 1990 年代以來(lái),Microsoft 開(kāi)始為其一系列專有的文字處理格式使用 .doc 擴(kuò)展名。Doc 格式通常與 Microsoft Office 應(yīng)用程序相關(guān)聯(lián)。但是在 Doc 文件中存儲(chǔ)文本并不總是很方便,因?yàn)樗鼈兣c大多數(shù)第三方文本編輯器不兼容。為了使 Doc 信息更易于訪問(wèn),最好將其存儲(chǔ)為其他更常見(jiàn)的格式。用戶通常選擇 RTF 格式,因?yàn)樗艿綇V泛的應(yīng)用程序的支持。
Spire.Doc for .NET 可以在您的系統(tǒng)上不安裝 Microsoft Office 的情況下將 Word 轉(zhuǎn)換為 RTF。使用 .NET Framework 2.0(或更高版本)下載Spire.Doc(或Spire.Office),然后按照以下簡(jiǎn)單步驟將 Word 轉(zhuǎn)換為 RTF。
第 1 步:通過(guò) Visual Studio 創(chuàng)建一個(gè)項(xiàng)目并添加 Spire.Doc DLL 作為參考。
第 2 步:加載我們需要轉(zhuǎn)換為 RTF 格式的本地 Word doc 文件。使用下面的代碼加載 Word 文件。
Document document = new Document(); document.LoadFromFile(@"D:\Sample.doc");
第 3 步:Spire.Doc 允許用戶將 Word doc 文件轉(zhuǎn)換為大多數(shù)流行的文件格式,包括 PDF、HTML、RTF、EPub、XML、Dot、Text 等。以下代碼可以幫助我們將 Word 轉(zhuǎn)換為 RTF。
document.SaveToFile("Sample.rtf", FileFormat.Rtf);
第 4 步:將下面的完整代碼復(fù)制到項(xiàng)目中,然后按 F5 啟動(dòng)項(xiàng)目。
完整代碼:
[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
有效截圖:
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn