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

J.Kuai

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在没有Microsoft.Office.Interop的.NET Core中将Word doc和docx格式转换为PDF

Microsoft.Office.Interop.Word OMath

我们如何在XSLT中将Microsoft Word DOCX文件转换为HTML?

如何在php中将html文件转换为word文件

在VBScript中使用Microsoft.Office.Interop.Word枚举常量

C# Microsoft.Office.Interop.Word 保护段落

使用Microsoft.Office.Interop Word和Excel

使用f#Microsoft.Office.Interop.Word搜索和替换

使用参考C#添加Microsoft.Office.InterOp.Word

Microsoft.Interop.Office.Word完整样式不适用

我如何创建接口Microsoft.Office.Interop.Word.Application的新实例

如何使用 Microsoft.Office.Interop.Word 在 C# 中编辑 docx 文件

如何使用Microsoft.Office.Interop.Word库删除输出中的段落间距

使用Microsoft.Office.Interop.Word启用内置的Microsoft Word按钮控件

如何在Microsoft Word中将小写文本转换为大写文本?

机器中的单独Microsoft.Office.Interop.Word实例和Word应用程序

是否可以使用Microsoft.Office.Interop.Word以编程方式从Word文档中删除行号?

Microsoft.Office.Interop.Word - Word 在尝试打开文件时遇到错误

C# Microsoft.Office.Interop.Word 替换为 Selection.Find.Execute() 超过第一个单词

如何在ASP.NET MVC中将HTML即时转换为Word文档?

如何在 Dart 中将 Word 文档转换为 PDF

如何在宏(Word)中将字母转换为上标?

如何在ROR中将Word文件转换为PDF

c# 如何在 Microsoft Interop Word 中编写

无法使用microsoft.office.interop.word在当前一字之后插入图像

可以将DebuggerDisplay属性应用于Microsoft.Office.Interop.Word.Range吗?

Microsoft.Office.Interop.Word.WdRelativeHorizontalPosition出现C#编译器错误;

Microsoft.Office.Interop.Word中仅可访问的第一页

在哪里可以找到Microsoft.Office.Interop.Word.dll(2010)?