The code is as follows: public TextSegment searchText(String searched, PositionInParagraph startPos) { ... int beginRunPos = 0, candCharPos = 0; for (int runPos = startRun; runPos < rArray.length; runPos++) { int beginTextPos = 0, beginCharPos = 0, textPos = 0, charPos; .... } beginTextPos and beginCharPos are in the loop and can be wrongly reset. NPOI fixed a similar bug: https://github.com/nissl-lab/npoi/commit/38cdadd3a67e59e6bede7f77996fbf048c5ffc7e In NPOI, the fixed code is as follows: public TextSegment SearchText(String searched, PositionInParagraph startPos){ ... int beginRunPos = 0, beginTextPos = 0, beginCharPos = 0,candCharPos = 0; for (int runPos = startRun; runPos < paragraph.GetRList().Count; runPos++){ int beginTextPos = 0, beginCharPos = 0, textPos = 0, charPos = 0; ... }
We are not going to just copy NPOI. Please provide real world examples. POI is a volunteer project and it is normally best to provide a patch with a test case yourself.