我在两个不同的项目中使用 Apache POI
第一个项目是一个独立的 Java 应用程序。这里一切都很好。
第二个项目是Android项目。我可以很好地访问 xlsx 的工作簿,但是在计算公式时,它会因异常而崩溃
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 应用程序上运行良好....
最佳答案
Android 使用的 ICU 正则表达式库与 Java 正则表达式引擎有点不同。
参见 this reference :
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}");
关于java - 使用 apache poi 的 PatternSyntaxException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38376190/