我的诉求是需要检查文档里面的样式信息,兼容模式读取样式信息有时候是错误的,页码也是乱的,或者根本读取不到。
@zchong 不幸的是,没有文件,很难分析这个问题。作为一种变体,您可以尝试使用以下代码加载文档:
LoadOptions options = new LoadOptions();
options.LanguagePreferences.DefaultEditingLanguage = EditingLanguage.ChinesePRC;
Document doc = new Document("input.docx", options);
@zchong 此外,docx 文件中的 settings.xml 包含以下兼容文件信息:
<w:compatSetting w:name="compatibilityMode" w:uri="http://schemas.microsoft.com/office/word" w:val="14"/>
您可以检查该值,并在兼容性设置中选择最佳的 MS Word 版本。 如果没有帮助,可能是 Aspose.Words 中的问题。
@zchong 感谢您提供的文件。 我还以为是关于 Aspose.Words 的问题。
本文件有
<w:compatSetting w:name="compatibilityMode" w:uri="http://schemas.microsoft.com/office/word" w:val="14"/>
这意味着它最兼容 Word 2010。 2010 和 2019 或更高版本在显示内容方面有很大区别。 但如果表格行列位置相同,两个版本都会出现相同的蓝线。
我认为没有问题,只是MS Word版本之间的计算和显示内容不同。
@zchong 正如我在上一篇文章中所说,转换后不可能得到相同的结果。 您可以调整表格的大小,尝试得到相似的结果。 下面是我修改后的转换文档。 虽然看起来和之前的不一样,但已经尽可能相似了:
converted.docx (30.1 KB)
这串xml属性有没有示例代码可以直接读取呢,帮忙提供下吧
顺便帮忙看下有没有办法获取制作当前文档的版本号,是2010、2016还是什么。
为什么会出现这种兼容模式呢。
@zchong Aspose.Words 没有获取此参数的特定代码。 您可以尝试使用 DocumentFormat.OpenXml 库来获取该值,然后用它来定义一些选项:
using (WordprocessingDocument wordDoc = WordprocessingDocument.Open("input.docx", false))
{
DocumentSettingsPart settingsPart = wordDoc.MainDocumentPart.DocumentSettingsPart;
Settings settings = settingsPart.Settings;
var compatibility = settings.GetFirstChild<Compatibility>();
var compatSetting = compatibility.GetFirstChild<CompatibilitySetting>();
if (compatSetting != null)
{
Console.WriteLine("Compatibility Mode Found:");
Console.WriteLine($"Name: {compatSetting.Name}");
Console.WriteLine($"Value: {compatSetting.Val}");
}
else
{
Console.WriteLine("Compatibility Mode setting not found.");
}
}
如果手动操作,需要将 .docx 改为 .zip,然后解压文件,在"{文件名}\word "文件夹中找到 settings.xml。
@zchong MS Word 兼容版本的默认值为 15。 您可以从提供的微软文档中查看: WdCompatibilityMode enumeration (Word) | Microsoft Learn
您提供的图像具有以下属性 mc:Ignorable Attribute - WPF .NET Framework | Microsoft Learn, 但不是兼容版本。
您好,我想咨询下java读取兼容模式的方式,通过debug的方式可以获取到版本号
Document document = new Document(bufferedInputStream, options);
document.getCompatibilityOptions().getMswVersion();
但是在代码行里面提示不存在getMswVersion该方法,请问我应该怎么读取12,14,15这种。
@zchong 感谢您提供的文件。 我没有理解正确。 我为您提供了代码,它可以获取文档将使用的 MS Word 版本,该版本存储在"16.0000"中。 但你需要的值来自 <w:compatSetting w:name="compatibilityMode" w:uri="http://schemas.microsoft.com/office/word" w:val="14"/>
。
我们已经在我们的内部问题跟踪系统中打开了以下新工单,并将根据 免费支持政策 中提到的条款提供它们的修复:
Issue ID(s): WORDSNET-28175
如果您需要优先支持以及直接联系我们的付费支持管理团队,您可以获得 付费支持服务 。