由于 Java 11 环境中缺少 fontconfig,Apache POI 在 createsheet 中失败

问题描述 投票:0回答:1

我们使用的是 Java 11,与早期版本的 Java 相比,Java 11 已从 jre/lib 中删除了 fonts 文件夹。 因此,由于缺少 fontconfig,我们的 poi 调用在 createsheet 调用时失败。 如果我们使用 yum 安装 fontconfig ,它会像 charm 一样工作。但是管理层不批准同样的操作。 Java8 中不会出现问题,因为字体是从 jre/lib 文件夹中识别的。 尝试将字体放入当前工作目录中,但这也没有帮助我们。 谁能告诉我,poi 如何获取字体,从哪里以及我可以做什么来克服这个问题。还有解决这个问题的字体/文件列表。

问候, 拉希

java apache-poi
1个回答
0
投票

深入研究 POI(版本 5.2.3)中的代码后,我在

org.apache.poi.ss.util.SheetUtil
中找到了这个:

/**
 * A system property which can be enabled to not fail when the
 * font-system is not available on the current machine
 */
private static final boolean ignoreMissingFontSystem =
        Boolean.parseBoolean(System.getProperty("org.apache.poi.ss.ignoreMissingFontSystem"));

将系统属性

org.apache.poi.ss.ignoreMissingFontSystem
设置为
true
已经为我解决了这个问题:

// avoid exceptions on systems without MS Fonts
System.setProperty("org.apache.poi.ss.ignoreMissingFontSystem", "true")
© www.soinside.com 2019 - 2024. All rights reserved.