调用方式:
// Load the Word document
Document doc = new Document(“New_境外资金月度分析简报2024-06-03.docx”);
doc.updateFields();
doc.updatePageLayout();
doc.save(“New_2境外资金月度分析简报.docx”);
@JOOL 当我重置字体设置时,在 Windows 和 MacOS 上都能重现这个问题。因此,您的电脑存在字体问题。请使用以下代码查找遗漏的字体:
public void fonts() throws Exception {
LoadOptions loadOptions = new LoadOptions();
loadOptions.getLanguagePreferences().setDefaultEditingLanguage(EditingLanguage.CHINESE_PRC);
Document doc = new Document("input.docx", loadOptions);
FontSubstitutionWarningCollector callback = new FontSubstitutionWarningCollector();
doc.setWarningCallback(callback);
doc.updateFields();
doc.updatePageLayout();
doc.save("output.docx");
}
private static class FontSubstitutionWarningCollector implements IWarningCallback {
///
/// Called every time a warning occurs during loading/saving.
///
public void warning(WarningInfo info) {
if (info.getWarningType() == WarningType.FONT_SUBSTITUTION)
System.out.println(info.getDescription());
}
}