2011-03-07 57 views

回答

2

如果Word互操作是一個選項,並且您擁有Word 2007或Word 2010,那麼您可以讓Word自己爲您作爲普通的另存爲。

例子:

http://msdn.microsoft.com/en-us/library/bb412305(v=office.12).aspx

報價示例代碼上面的鏈接:

try 
{ 
    // Open the source document. 
    wordDocument = wordApplication.Documents.Open(
     ref paramSourceDocPath, ref paramMissing, ref paramMissing, 
     ref paramMissing, ref paramMissing, ref paramMissing, 
     ref paramMissing, ref paramMissing, ref paramMissing, 
     ref paramMissing, ref paramMissing, ref paramMissing, 
     ref paramMissing, ref paramMissing, ref paramMissing, 
     ref paramMissing); 

    // Export it in the specified format. 
    if (wordDocument != null) 
     wordDocument.ExportAsFixedFormat(paramExportFilePath, 
      paramExportFormat, paramOpenAfterExport, 
      paramExportOptimizeFor, paramExportRange, paramStartPage, 
      paramEndPage, paramExportItem, paramIncludeDocProps, 
      paramKeepIRM, paramCreateBookmarks, paramDocStructureTags, 
      paramBitmapMissingFonts, paramUseISO19005_1, 
      ref paramMissing); 
} 
catch (Exception ex) 
{ 
    // Respond to the error 
} 
finally 
{ 
    // Close and release the Document object. 
    if (wordDocument != null) 
    { 
     wordDocument.Close(ref paramMissing, ref paramMissing, 
      ref paramMissing); 
     wordDocument = null; 
    } 

    // Quit Word and release the ApplicationClass object. 
    if (wordApplication != null) 
    { 
     wordApplication.Quit(ref paramMissing, ref paramMissing, 
      ref paramMissing); 
     wordApplication = null; 
    } 

    GC.Collect(); 
    GC.WaitForPendingFinalizers(); 
    GC.Collect(); 
    GC.WaitForPendingFinalizers(); 
}