//轉化
private static void WordToHtmlFile(string WordFilePath)
...{
try
...{
Microsoft.Office.Interop.Word.Application newApp = new Microsoft.Office.Interop.Word.Application();
// 指定原文件和目標文件
object Source = WordFilePath;
string SaveHtmlPath = WordFilePath.Substring(0, WordFilePath.Length - 3) + "Html";
object Target = SaveHtmlPath;
// 缺省參數
object Unknown = Type.Missing;
//為了保險,只讀方式打開
object readOnly = true;
// 打開doc文件
Microsoft.Office.Interop.Word.Document doc
= newApp.Documents.Open(ref Source, ref Unknown,
ref readOnly, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown);
// 指定另存為格式(rtf)
object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHtml;
// 轉換格式
doc.SaveAs(ref Target, ref format,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown);
// 關閉文檔和Word程序
doc.Close(ref Unknown, ref Unknown, ref Unknown);
newApp.Quit(ref Unknown, ref Unknown, ref Unknown);
}
catch(Exception e)
...{
System.Windows.Forms.MessageBox.Show(e.Message);
}
}
}
}