关于Word转HTML时修订人/批注人显示不正确的问题

 public void wordToHtml(String sourceFileName, String newFileName) {
        HtmlFixedSaveOptions htmlFixedSaveOptions = new HtmlFixedSaveOptions();
        htmlFixedSaveOptions.setExportEmbeddedCss(true);
        htmlFixedSaveOptions.setExportEmbeddedFonts(true);
        htmlFixedSaveOptions.setExportEmbeddedImages(true);
        htmlFixedSaveOptions.setShowPageBorder(false);
        // Load DOC file to be converted
        Document wpd = new Document(sourceFileName);
        wpd.save(newFileName, htmlFixedSaveOptions);       
}

使用上方代码将word转成html时,批注人/修订人显示不正确,原文档中批注人是“张三”,而转成html以后就变成了Commented [CM1]之类的,请问如何能让批注人正确显示

@baifang 您能否在此处附上您的输入文档和预期输出的屏幕截图? 我们将检查问题并为您提供更多信息。
此外,您可以使用 RevisionOptions 类来配置在布局过程中如何处理文档修订。

企业微信截图_16405863891353.png (447.5 KB)

result_抚州市投资发展(集团)有限公司2021年度第二期中期票据募集说明书.docx (1.3 MB)

您好,原文档和期望的输出截图均已以附件的形式上传!请您查收,辛苦您了!我也会仔细查看您推荐的RevisionOptions类。再次感谢您的回复!

正如我所看到的 Aspose.Words 在这里遵循 MS Word 的行为。 如果使用 MS Word 转换您的文档或 PDF,注释看起来与 Aspose.Words 生成的 PDF 完全一样。
但是,您可以指定线程的文化,以使评论看起来更接近您需要的内容:

CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = new CultureInfo("zh-Hans");

Document doc = new Document(@"C:\Temp\in.docx");
doc.Save(@"C:\Temp\out.pdf");

Thread.CurrentThread.CurrentCulture = currentCulture;

是的,目前看来Aspose.Words已经很完美地在html中还原了word的样子,但是我仍然希望转出来的html中,“批注人/修订人”和原word保持一致。在我的原word文档中,批注人是“蜂投精灵”,但是在转出来的html中,取而代之的是Commented [CM1],我不知道是哪里出现了问题,在HtmlFixedSaveOptions和 RevisionOptions中似乎也没有相关的设置可以更换批注人的名称,以使“Commented [CM1]”变成“蜂投精灵”

@baifang MS Word 和 Aspose.Words 都显示评论作者的姓名首字母。 请查看您文档中的 XML,因为您会注意到首字母缩写为 CM。

	<w:comment w:id="118" w:author="蜂投精灵" w:date="2021-12-24T10:51:17Z" w:initials="CM">
		<w:p d3p1:paraId="009896D9" xmlns:d3p1="http://schemas.microsoft.com/office/word/2010/wordml">
			<w:pPr />
			<w:r>
				<w:t xml:space="preserve">发行人 2018年报 预收款项=280814.88≠375,159.27</w:t>
			</w:r>
		</w:p>
	</w:comment>

您可以解决这个问题并使用如下代码显示作者插入的首字母:

CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = new CultureInfo("zh-Hans");

Document doc = new Document(@"C:\Temp\in.docx");

NodeCollection comments = doc.GetChildNodes(NodeType.Comment, true);
foreach (Comment c in comments)
    c.Initial = c.Author;

doc.Save(@"C:\Temp\out.html", SaveFormat.HtmlFixed);

Thread.CurrentThread.CurrentCulture = currentCulture;

非常感谢您的帮助!这个方法的确有用,可以显示出批注作者的信息。再次感谢您的帮助!谢谢!祝好!

微信图片_20220106105950.png (112.6 KB)

另外我还想咨询您一个问题。使用HtmlFixedSaveOptions配置word转html的效果非常好,几乎不需要设置额外的选项就可以完美还原word的样貌,但在某些场景下,我不需要将批注信息转换出来,我只想要转换正文,这时候我应该配置HtmlFixedSaveOptions的什么属性?(我使用过HtmlSaveOptions。使用HtmlSaveOptions作为配置转换,虽然右侧的批注信息不会被转换出来,但是正文的效果却远没有HtmlFixedSaveOptions那么好看,所以我更希望使用HtmlFixedSaveOptions)

再次感谢您的帮助与支持,谢谢!祝好!

@baifang 您应该设置 CommentDisplayMode.Hide。 请看下面的代码示例:

Document doc = new Document(@"C:\Temp\in.docx");
doc.LayoutOptions.CommentDisplayMode = Aspose.Words.Layout.CommentDisplayMode.Hide;
doc.Save(@"C:\Temp\out.html", SaveFormat.HtmlFixed);