string fileName = System.IO.Path.GetFileNameWithoutExtension(file.FileName);
Word.Application word = new Word.Application();
Type wordType = word.GetType();
Word.Documents docs = word.Documents;
Type docsType = docs.GetType();
//第二个参数设置为false,不打开word确认文件转换窗口,特别是在office2016的环境下
Word.Document doc = (Word.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { fullPath, false, true });
Type docType = doc.GetType();
if (Directory.Exists(Server.MapPath("~/html")) == false)
{
Directory.CreateDirectory(Server.MapPath("~/html"));
}
string strSaveFileName = Server.MapPath("~/html") + @"\" + fileName + ".html";
object saveFileName = (object)strSaveFileName;
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, Word.WdSaveFormat.wdFormatFilteredHTML });
docType.InvokeMember("Close", System.Reflection.BindingFlags.InvokeMethod, null, doc, null);
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);
C#word转html 不打开文件转换窗口
最新推荐文章于 2024-07-17 18:00:00 发布