使用 apache poi 的 PatternSyntaxException [英] PatternSyntaxException using apache poi

查看:32
本文介绍了使用 apache poi 的 PatternSyntaxException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在两个不同的项目中使用 Apache POI

I am using Apache POI in two different projects

第一个项目是一个独立的 Java 应用程序.这里一切都很好.

The first project is a standalone Java application. Everything is fine here.

第二个项目是一个安卓项目.我可以很好地访问 xlsx 的工作簿,但是在评估公式时,它会因异常而崩溃

The second project is an Android project. I can access the Workbook of an xlsx just fine, but when it comes to evaluating formulas, it crashes with an Exception

java.util.regex.PatternSyntaxException: U_ILLEGAL_ARGUMENT_ERROR \P{IsL}
   at java.util.regex.Pattern.compileImpl(Native Method)
   at java.util.regex.Pattern.compile(Pattern.java:411)
   at java.util.regex.Pattern.<init>(Pattern.java:394)
   at java.util.regex.Pattern.compile(Pattern.java:381)
   at org.apache.poi.ss.formula.functions.TextFunction$5.<init>(TextFunction.java:124)
   at org.apache.poi.ss.formula.functions.TextFunction.<clinit>(TextFunction.java:123)

这是有问题的代码行:

    final Pattern nonAlphabeticPattern = Pattern.compile("\\P{IsL}");

为什么Android不接受这个?正如我所说:它在独立的 Java 应用程序上运行良好......

Why does Android not accept this? As I said: It's working fine on a standalone Java application ....

推荐答案

Android 正在使用 ICU regex 库,这与 Java regex 引擎有点不同.

Android is using ICU regex library that is a bit different from Java regex engine.

请参阅此参考:

Unicode 脚本、块、类别和二进制属性是用 \p\P 结构编写的,就像在 Perl 中一样.\p{prop} 如果输入具有属性 prop 则匹配,而 \P{prop} 如果输入具有该属性则不匹配.

Unicode scripts, blocks, categories and binary properties are written with the \p and \P constructs as in Perl. \p{prop} matches if the input has the property prop, while \P{prop} does not match if the input has that property.

因此,模式应该写成

Pattern nonAlphabeticPattern = Pattern.compile("\\P{L}"); 

这篇关于使用 apache poi 的 PatternSyntaxException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆