Good morning,
I am trying to clear an XWPFRun completely -- not removing it, but just setting it to an empty string. And I have no success if the run contains white space, for example tabs. I set up a very simple example (in Groovy, as this is the most easy and fastest way to showcase it, with dependencies) to reproduce this issue: https://github.com/paulwellnerbou/apache-poi-testcases/blob/main/run/clearRun.groovy How do I clear runs completely even with tab stops? Is this a bug in Apache POI XWPF or am I doing anything wron? Thank you very much! |
Hi,
Is the range in "for (i in 0..lastIndexOfTArray) {" including the last index? I.e. as you use "-1" in the line above, the check in the for-loop needs to be "<= lastIndexOfTArray". At least I had the same behavior in Java with "for (int i = 0; i < lastIndexOfArray; i++)", but it works fine with ">=". Regards... Dominik. On Mon, Dec 21, 2020 at 11:43 AM Paul Wellner Bou <[hidden email]> wrote: > Good morning, > > I am trying to clear an XWPFRun completely -- not removing it, but just > setting it to an empty string. And I have no success if the run contains > white space, for example tabs. > > I set up a very simple example (in Groovy, as this is the most easy and > fastest way to showcase it, with dependencies) to reproduce this issue: > > > https://github.com/paulwellnerbou/apache-poi-testcases/blob/main/run/clearRun.groovy > > How do I clear runs completely even with tab stops? Is this a bug in > Apache POI XWPF or am I doing anything wron? > > Thank you very much! > |
Hello,
thank you. Unfortunately, this does not help. I changed the example and added more output. Let's say we take run[1] of this paragraph: def run = nameParagraph.runs[1] println("run text: '"+ run.text()+"'") def lastIndexOfTArray = run.CTR.sizeOfTArray() println("lastIndexOfTArray: " + lastIndexOfTArray) for (i in 0..lastIndexOfTArray) { println(i+ ":'" + run.getText(i)+"'") run.setText("", i) } This will correctly print the whitespace, but getText(i) is always null: > run text: ' ' > lastIndexOfTArray: 0 > 0:'null' And setText seems to work, but this won't replace the whitespace. Where can I find the whitespace in this run, and how to I overwrite it? Thank you and Kind regards Paul. ________________________________ From: Dominik Stadler <[hidden email]> Sent: Monday, December 21, 2020 10:38 PM To: POI Developers List <[hidden email]> Subject: Re: XWPF: Clearing a run containing white space Hi, Is the range in "for (i in 0..lastIndexOfTArray) {" including the last index? I.e. as you use "-1" in the line above, the check in the for-loop needs to be "<= lastIndexOfTArray". At least I had the same behavior in Java with "for (int i = 0; i < lastIndexOfArray; i++)", but it works fine with ">=". Regards... Dominik. On Mon, Dec 21, 2020 at 11:43 AM Paul Wellner Bou <[hidden email]> wrote: > Good morning, > > I am trying to clear an XWPFRun completely -- not removing it, but just > setting it to an empty string. And I have no success if the run contains > white space, for example tabs. > > I set up a very simple example (in Groovy, as this is the most easy and > fastest way to showcase it, with dependencies) to reproduce this issue: > > > https://github.com/paulwellnerbou/apache-poi-testcases/blob/main/run/clearRun.groovy > > How do I clear runs completely even with tab stops? Is this a bug in > Apache POI XWPF or am I doing anything wron? > > Thank you very much! > |
Free forum by Nabble | Edit this page |