You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by an...@superlinksoftware.com on 2005/04/27 07:40:58 UTC

HWPF issues

Hey guys,

Has anyone tried the latest HWPF stuff recently?  I seem to be creating 
invalid simple text sequences.  Meaning when I say "insertAfter" or 
"insertBefore" all the spaces are converted to ??.  I ran HexDump on it 
and the text sequences look the same.

here's my code (below).  I pass the 
jakarta-poi/src/scratchpad/testcases/org/apache/poi/hwpf/data/test.doc 
and an ouput file as the arguments.  I tried it both the commented out 
and uncommented permutations.  (note: I made the cloneProperties() but 
that didn't cause this problem at least -- when I didn't clone it from 
an existing character run I kept ending up with bookmarks)  Am I missing 
something?

package com.superlink.poi.test;

import org.apache.poi.hwpf.*;
import org.apache.poi.hwpf.usermodel.*;
import org.apache.poi.util.HexDump;

import java.io.*;

public class HWPFTest {

     public static void main(String[] args) {
         try {
             if (args.length > 2) {
                 FileInputStream in = new FileInputStream(args[0]);
                 HWPFDocument doc = new HWPFDocument(in);
                 ByteArrayOutputStream bos = new ByteArrayOutputStream();
                 doc.write(bos);
                 System.out.println(HexDump.dump(bos.toByteArray(),0,0));
                 in.close();
             } else {
                 FileInputStream in = new FileInputStream(args[0]);
                 HWPFDocument doc = new HWPFDocument(in);
                 Range r = doc.getRange();
                 CharacterRun run = r.getSection(0).getCharacterRun(0);
                 run.insertAfter("this is random text inserted by 
andy",run.cloneProperties());
                 System.out.println(r.text());
           //      r.insertBefore("This is a random piece of text 
inserted by andy.");
                 FileOutputStream out = new FileOutputStream(args[1]);
                 doc.write(out);
                 in.close();
                 out.close();
             }
         } catch (Exception e) {
             e.printStackTrace();
         }
     }
}

the delta:

...
 > 00000600 54 00 68 00 69 00 73 00 20 00 69 00 73 00 20 00 T.h.i.s. .i.s. .
 > 00000610 61 00 20 00 72 00 61 00 6E 00 64 00 6F 00 6D 00 a. .r.a.n.d.o.m.
 > 00000620 20 00 70 00 69 00 65 00 63 00 65 00 20 00 6F 00  .p.i.e.c.e. .o.
 > 00000630 66 00 20 00 74 00 65 00 78 00 74 00 20 00 69 00 f. .t.e.x.t. .i.
 > 00000640 6E 00 73 00 65 00 72 00 74 00 65 00 64 00 20 00 n.s.e.r.t.e.d. .
 > 00000650 62 00 79 00 20 00 61 00 6E 00 64 00 79 00 2E 00 b.y. .a.n.d.y...
 > 00000660 13 00 20 00 53 00 45 00 51 00 20 00 43 00 48 00 .. .S.E.Q. .C.H.
 > 00000670 41 00 50 00 54 00 45 00 52 00 20 00 5C 00 68 00 A.P.T.E.R. .\.h.
 > 00000680 20 00 5C 00 72 00 20 00 31 00 15 00 4D 00 79 00  .\.r. .1...M.y.
 > 00000690 20 00 6E 00 61 00 6D 00 65 00 20 00 69 00 73 00  .n.a.m.e. .i.s.
 > 000006A0 20 00 52 00 79 00 61 00 6E 00 20 00 54 00 68 00  .R.y.a.n. .T.h.
 > 000006B0 69 00 73 00 20 00 69 00 73 00 20 00 61 00 20 00 i.s. .i.s. .a. .
 > 000006C0 74 00 65 00 73 00 74 00 20 00 62 00 6C 00 61 00 t.e.s.t. .b.l.a.
 > 000006D0 68 00 62 00 6C 00 61 00 68 00 62 00 6C 00 61 00 h.b.l.a.h.b.l.a.
 > 000006E0 79 00 68 00 20 00 54 00 68 00 69 00 73 00 20 00 y.h. .T.h.i.s. .
...

Notice how it at least looks like the spaces are the right character 
code.  They also look like the already existing text below.

If anyone has some insite I'd appreciate it.

-Andy

---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/