繁体   English   中英

如何通过Microsoft.Office.Interop.Word将wdRevisionsViewFinal中的word转换为html?

[英]How to convert word to html in wdRevisionsViewFinal by Microsoft.Office.Interop.Word?

我可以通过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);

这是处于审阅模式下的文档的屏幕快照。 eqQ4Ds.md.jpg

这是我的转换html屏幕截图。

eqlMPf.md.jpg

这是没有审阅模式屏幕截图的文档。(无下划线,边框等) eqQBDA.jpg

非常感谢所有帮助过的人。

保存前只需.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();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM