0

我们正在将一个项目从 Jxls 1.x 迁移到 Jxls 2.2.8。在我们当前的模板中,我们使用 Spring MessageSource 使用 messageSource.getMessage("message.key", locale) 来本地化报告的标题。它适用于 1.x 版本,但在 2.x 版本中它不解析消息。

这是我们当前的模板

当方法有参数时消息解析失败,但是当我们在 messageSource 对象中调用 toString() 方法时,它会起作用并在单元格中打印字符串。

我们班的代码是:

public void convertToXLS(final Map<String, Object> p_model, final InputStream p_template, final OutputStream p_file, final Locale p_locale) throws InvalidFormatException, IOException {
    DeviceEventsDownloadWebModel deviceEventsDownloadWebModel = (DeviceEventsDownloadWebModel) p_model.get("deviceEventsDownloadWebModel");

Context context = new Context();
context.putVar("messageSource", getMessageSource());
context.putVar("locale", p_locale);
context.putVar("deviceEvents", deviceEventsDownloadWebModel.getDeviceEvents());

JxlsHelper.getInstance().processTemplate(p_template, p_file, context);
}

有什么解决问题的建议吗?我们也尝试将 messageSource 设置为一个函数,但它不起作用。

4

1 回答 1

0

解决了!我们已经发现了问题。MessageSource 类的 getMessage() 方法具有签名:String 键、Object[] 参数、Locale 语言环境,我们只传递了 2 个参数。

于 2016-01-22T13:28:45.553 回答