如何用C#把Doc文檔轉(zhuǎn)換成rtf格式
發(fā)表時(shí)間:2024-01-22 來(lái)源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]來(lái)自:CSDN先在項(xiàng)目引用里添加上對(duì)Microsoft Word 9.0 object library的引用。 using System; namespace DocConvert class DoctoRtf static void Main() //創(chuàng)建一個(gè)word的實(shí)...
來(lái)自:CSDN
先在項(xiàng)目引用里添加上對(duì)Microsoft Word 9.0 object library的引用。
using System;
namespace DocConvert
{
class DoctoRtf
{
static void Main()
{
//創(chuàng)建一個(gè)word的實(shí)例
Word.Application newApp = new Word.Application();
// 指定源文件和目標(biāo)文件
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實(shí)例
newApp.Quit(ref Unknown,ref Unknown,ref Unknown);
}
}
}