UTF-8导出与xwpf不一致

huangapple go评论107阅读模式
英文:

UTF-8 export with xwpf inconsistent

问题

我正在使用Office 2013上的XWPF Apache的POI库进行模板编辑。我在使用IntelIJ IDE。

当我在IDE环境中进行测试并运行程序时,一切正常:模板被很好地编码。但是当我导出jar文件时,一切也运行良好,但所有的重音都被破坏了。

我已经在我的项目中四处寻找,问题不在模板也不在内容数据上,而是在导出过程中。有人之前遇到过这种情况吗?我该怎么办?

注意:我已经尝试过在Eclipse中进行测试,我遇到了相同的问题,这不是IDE配置问题或构建问题。

我没有太多的代码可以向您展示:对于这个问题,没有什么真正相关的东西。我正在使用这个方法来导出.docx文件:
POIXMLDocument#write(OutputStream)

感谢您的帮助。

我尝试过使用这个方法(https://stackoverflow.com/questions/24564028/encoding-issue-with-apache-poi),对每个文本替换都使用了它,但似乎不起作用。

英文:

I'm doing template-edition with XWPF apache's POI lib on Office 2013. I'm using IntelIJ IDE.

When I'm doing my tests and run program in the IDE environment, everything works great: template is well encoded. But when I export the jar, everything works well too, but all accents are destroyed.

I have been seeking around my project, and it's not about the template nor the content data, but during the exportation. Has someone seen it before? What should I do?

Note: I've tested with Eclipse and I have the same problem, it's not an IDE configuration problem nor a build one.

There is not so much code I can show you: there is nothing really relevant for this problem. I'm using this method to export the .docx:
POIXMLDocument#write(OutputStream)

Thanks for the help.

I tried to use that method (https://stackoverflow.com/questions/24564028/encoding-issue-with-apache-poi), on every text replacement but it doesn't seem to work.

答案1

得分: 0

抱歉,我在这个问题 https://stackoverflow.com/questions/41829890/encoding-issue-with-apache-poi-converter 找到了一个解决方案。

显然,你需要这样做:String theNewString = URLDecoder.decode(URLEncoder.encode(new String(oldString.getBytes(), StandardCharsets.UTF_8), "UTF-8"), "UTF-8")

祝你有美好的一天。

英文:

Ok sorry, i've found a solution on this question https://stackoverflow.com/questions/41829890/encoding-issue-with-apache-poi-converter.

Apparantly, you have to do this : String theNewString = URLDecoder.decode(URLEncoder.encode(new String(oldString.getBytes(), StandardCharsets.UTF_8), "UTF-8"), "UTF-8").

Have a good day.

huangapple
  • 本文由 发表于 2020年8月15日 17:14:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/63424424.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定