Created attachment 37107 [details] Add testUtfDecode_withApplyFont and patch XSSFRichTextString.getFormatMap If you use `applyFont()` for `XSSFRichString` having unicode representation _xHHHH_ format, an IllegalArgumentException is thrown. `testUtfDecode_withApplyFont` is a new test made by myself, also in the patch. > Text length was 8 but the last format index was 20 > java.lang.IllegalArgumentException: Text length was 8 but the last format index was 20 > at org.apache.poi.xssf.usermodel.XSSFRichTextString.buildCTRst(XSSFRichTextString.java:590) > at org.apache.poi.xssf.usermodel.XSSFRichTextString.applyFont(XSSFRichTextString.java:157) > at org.apache.poi.xssf.usermodel.XSSFRichTextString.applyFont(XSSFRichTextString.java:167) > at org.apache.poi.xssf.usermodel.TestXSSFRichTextString.testUtfDecode_withApplyFont(TestXSSFRichTextString.java:269) > ... So I modified `XSSFRichTextString.getFormatMap()` to sum length after utf-decoded. Then the test and all tests are passed well. Actually, I have an original xlsx file that makes this problem, but due to the security reason, I can't share the file. I think someone can help making MWE.
Fixed via r1875571, I ended up adding a more optimized utfLength() method which avoids constructing the full replaced string when only the resulting length is required.
Thanks a lot, and looking forward to release soon. :)
Suggestion: add this ticket to History of Changes http://poi.apache.org/changes.html#5.0.0
The changelog is now updated with some more entries that were missing.