【发布时间】:2016-05-05 11:24:49
【问题描述】:
我正在将.doc 文件转换为 HTML 文件,这工作得非常好,但我需要实现的一件事是 HTML 文件的格式必须与“打印”中 Word 文件的格式相同布局”格式。
如果我能以某种方式将页脚信息(即每页的页码)添加到转换后的 HTML 文件中,那么我的工作就完成了。
Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
oWord.Documents.Open(ref FileName, ref ReadOnly, ref MissingType,
ref MissingType, ref MissingType, ref MissingType,
ref MissingType, ref MissingType, ref MissingType,
ref MissingType, ref IsVisible, ref MissingType,
ref MissingType, ref MissingType, ref MissingType,
ref MissingType);
var oWordDoc = oWord.ActiveDocument;
oWordDoc.SaveAs(ref HtmlDirectoryPath, ref DocumentFormat, ref MissingType, ref MissingType,
ref MissingType, ref MissingType, ref MissingType, ref MissingType, ref MissingType,
ref MissingType, ref MissingType, ref MissingType, ref MissingType, ref MissingType,
ref MissingType, ref MissingType);
当我看到HTML文件时,它与Word的“Web Layout”模式相同,我不想要。
我正在使用 C# 和 Microsoft.Office.Interop.Word 库进行此转换。
更新 1:如您所见,查看 Word 文档文件有三种模式 - 阅读模式、打印布局和 Web 布局。但是当我使用上述代码转换文件时,生成的 HTML 文件内容与 Word 文档的 Web 布局模式相同。因此,当有人阅读该 HTML 文件并想向起草文件的人报告一些错误或错误时,有一个不正确的日期并且您必须更新它,那么就不知道在哪个页面上正是错误/错误。因为在 HTML 格式中没有显示页面信息。
所以我的工作是按照pagewise在转换后的HTML中添加一些页面信息,以便验证者可以很容易地告诉起草者我已经浏览了文件并且在Page No X上有一个日期更正。
我尝试将页码添加到文档页脚中,但是当我将其转换为 HTML 时,没有页脚信息随之转换。
【问题讨论】:
-
"当我看到HTMl文件时,和word的"Web Layout"模式一样。"请说明你的意思,不清楚
-
嗯,HTML 没有“页面”的概念,因此要求与技术的设计工作方式不一致。因此,将 Word 文档另存为 HTML 不会生成任何页码或其他页脚内容,也无法强制 SaveAs 这样做。解决方案将涉及您的代码“遍历”文档,并以某种方式将来自页脚的信息放入页面末尾的文档中。由于这会改变页面流程,因此您需要从文档末尾开始工作。然后保存文档。
标签: c#-4.0 office-interop