明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

如何用C#把Doc文檔轉(zhuǎn)換成rtf格式

[摘要]來(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);

  }
 }
}