C# codepublic void wordchangetohtml(string sourcepath, string htmlpath)
{
try
{
Word.ApplicationClass word = new Word.ApplicationClass();
Type wordType = word.GetType();
Word.Documents docs = word.Documents;
// 打开文件
Type docsType = docs.GetType();
object fileName = sourcepath;
Word.Document doc = (Word.Document)docsType.InvokeMember("Open",
System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { fileName, true, true });
// 转换格式,另存为
Type docType = doc.GetType();
object saveFileName = htmlpath;
///wdFormatUnicodeText
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, Word.WdSaveFormat.wdFormatHTML });
// 退出 Word
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);
}
catch (Exception EX)
{
throw EX;
}
}