我可以通过 Microsoft.Office.Interop.Word 将 word 转换为 html。但是,由于文档中的评论注释,转换后的 HTML 中存在大量标记信息。如何在无审阅模式下转换 HTML?
这是我的转换代码,如何修复?
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
Type wordType = word.GetType();
Microsoft.Office.Interop.Word.Documents docs =word.Documents;
Type docsType = docs.GetType();
//aPath is the document file path
object fileName = aPath;
Microsoft.Office.Interop.Word.Document doc = (Microsoft.Office.Interop.Word.DocumentdocsType.InvokeMember("Open",
System.Reflection.BindingFlags.InvokeMethod, null,docs, new Object[] { fileName, true, true });
Type docType = doc.GetType();
string ConfigPath = string.Format("{0}.html",aPath);
object saveFileName = ConfigPath;
docType.InvokeMember("SaveAs",System.Reflection.BindingFlags.InvokeMethod,
null, doc, new object[] { saveFileName,Microsoft.Office.Interop.Word.WdSaveFormatwdFormatHTML });
docType.InvokeMember("Close",System.Reflection.BindingFlags.InvokeMethod,
null, doc, new object[] { null, null, null });
wordType.InvokeMember("Quit",System.Reflection.BindingFlags.InvokeMethod, null,word, null);
这是我的转换 html 屏幕截图。
这是他没有审查模式截图的文件。(没有下划线,边框等)
非常感谢所有帮助过的人。
就在.DeleteAllComments()
保存之前:
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Documents docs = word.Documents;
Microsoft.Office.Interop.Word.Document doc = docs.Open("c:/temp/test.docx");
object saveFileName = "c:/temp/test.html";
doc.DeleteAllComments();
doc.SaveAs2(saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML);
doc.Close();
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句