如何用C#把Doc文檔轉(zhuǎn)換成rtf格式
發(fā)表時間:2024-05-29 來源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]來自:CSDN先在項目引用里添加上對Microsoft Word 9.0 object library的引用。 using System; namespace DocConvert class DoctoRtf static void Main() //創(chuàng)建一個word的實...
來自:CSDN
先在項目引用里添加上對Microsoft Word 9.0 object library的引用。
using System;
namespace DocConvert
{
class DoctoRtf
{
static void Main()
{
//創(chuàng)建一個word的實例
Word.Application newApp = new Word.Application();
// 指定源文件和目標文件
object Source="c:\\abc\\Source.doc";
object Target="c:\\abc\\Target.rtf";
object Unknown =Type.Missing;
// 打開要轉(zhuǎn)換的Word文件
newApp.Documents.Open(ref Source,ref Unknown,
ref Unknown,ref Unknown,ref Unknown,
ref Unknown,ref Unknown,ref Unknown,
ref Unknown,ref Unknown,ref Unknown,
ref Unknown );
// 指定文檔的類型
object format = Word.WdSaveFormat.wdFormatRTF;
//改變文檔類型
newApp.ActiveDocument.SaveAs(ref Target,ref format,
ref Unknown,ref Unknown,ref Unknown,
ref Unknown,ref Unknown,ref Unknown,
ref Unknown,ref Unknown,ref Unknown);
//關(guān)閉word實例
newApp.Quit(ref Unknown,ref Unknown,ref Unknown);
}
}
}