为什么要将 Word 转换为 RTF/h5>
如何使用 Spire.Doc 将 Word 转换为 RTF/h5>
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 documentDocument 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.DocNamespace DOCRTFClass ProgramPrivate Shared Sub Main(args As String())End SubPrivate Sub button1_Click(sender As Object, e As EventArgs)'Create word documentDim 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 SubPrivate Sub WordDocViewer(fileName As String)TrySystem.Diagnostics.Process.Start(fileName)CatchEnd TryEnd SubEnd ClassEnd Namespace
有效截图:

欢迎下载|体验E-iceblue产品
如需获取更多产品信息,请您咨询在线客服
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!