You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2014/04/04 22:01:47 UTC

[Bug 56350] New: XWPFRun seperating text in the same format

https://issues.apache.org/bugzilla/show_bug.cgi?id=56350

            Bug ID: 56350
           Summary: XWPFRun seperating text in the same format
           Product: POI
           Version: unspecified
          Hardware: PC
            Status: NEW
          Severity: major
          Priority: P2
         Component: XWPF
          Assignee: dev@poi.apache.org
          Reporter: navaneethster@gmail.com

Created attachment 31477
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=31477&action=edit
the template word Document used in program.

I am trying to execute the code below

var doc = new XWPFDocument(OPCPackage.open(("D:\\template.docx")));

for ( p in doc.getParagraphs()) {
  for ( r in p.getRuns()) {
    var text = r.toString();
    print(text)
    if (text.contains("$ClaimNumber")) {
      text = text.replace("$ClaimNumber", claimRes.ClaimNumber);
      r.setText(text,0);
    }
   if (text.contains("$NoOfExposures")) {
      text = text.replace("$NoOfExposures", claimRes.Exposures.length);
      r.setText(text,0);
    }
  }
}

try {
  outStream = new FileOutputStream("D:\\templateoutput.docx");
} catch (e : FileNotFoundException ) {
  e.printStackTrace();
}

try {
  doc.write(outStream);
  print("File updated successfully")
  outStream.close();
} catch (e : FileNotFoundException ) {
  e.printStackTrace();
} catch (e :IOException ) {
  e.printStackTrace();
}

The output is 

The Claim Number is $
ClaimNumber
There are $
NoOfExposures
 Exposures
File updated successfully

It can be clearly seen that the problem is with the XWPFRun which is reading it
in a way that is not expected. I am trying to replace $ClaimNumber with the
actual Claim Number.
Since the Run is behaving in an unexpected manner the $ and the word
ClaimNumber is separated in to two runs which in turn fails to be replace in
the output.
Also if you look at the document its pretty simple and straight forward and
looking at it I can see that the entire Paragraph is in the Same format.
Which would make me assume that the Run is also in the same format. However
looking at the output it is not so. Please let me know how to resolve this.

PS : 
The above code is a Gosu Code.
However its easily convertible to Java and the variable ClaimRes usages can
also be replaced with any text

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 56350] XWPFRun seperating text in the same format

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=56350

Nick Burch <ap...@gagravarr.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Nick Burch <ap...@gagravarr.org> ---
That's not a bug in Apache POI, that's just a quirk of how word writes the
file. For some reason, Word has decided that the $ and the rest of your text
have/had/may-have-had different formatting, so split them into two runs

You'll need to tweak your logic to detect and cope with the case when the
search text spans several runs, then decide which run to replace in and which
to delete

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 56350] XWPFRun seperating text in the same format

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=56350

Navaneeth Anantharaman <na...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |navaneethster@gmail.com
                 OS|                            |All

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org