greetings,

my CharacterProperties are only being applied correctly about half the time -- which leaves me scratching my head. i've written a test that illustrates the problem. the below test outputs a document like this:

first
SECOND
third
FOURTH
fifth
sixth
seventh
eighth
ninth

obviously, "sixth" and "eighth" should also be in all caps. i get the same problem with applying color or highlights -- it works for the first half of the document, but then starts glitching.

any suggestions?

+ + +

import java.io.File;
import java.util.ArrayList;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.CharacterProperties;
import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.usermodel.Section;

public class WordDocumentTest {
        public static File BLANK = new File("resources/blank.doc");
        public static CharacterProperties cpA = new CharacterProperties();
        public static CharacterProperties cpB = new CharacterProperties();
    boolean toggle = false;

    static {
        cpA.setCapitalized(true);
        cpB.setCapitalized(false);
    }

        public static void main(String[] args) {
                ArrayList<String> lines = new ArrayList<String>();
                lines.add(0, "first");
                lines.add(0, "second");
                lines.add(0, "third");
                lines.add(0, "fourth");
                lines.add(0, "fifth");
                lines.add(0, "sixth");
                lines.add(0, "seventh");
                lines.add(0, "eighth");
                lines.add(0, "ninth");
                new WordDocumentTest("test1.doc", lines);
        }       
        
public WordDocumentTest(String filename, ArrayList<String> contents) {
        WordUtil.copy(BLANK, new File(filename));
        HWPFDocument document = WordUtil.read(filename);
        Section section = document.getRange().getSection(0);

        for(String line : contents) {
Paragraph p = section.insertBefore(document.getStyleSheet().getParagraphStyle(0), 0);
                p.insertBefore(line.toString(), (toggle ? cpA : cpB));
                toggle = !toggle;
        }

        WordUtil.write(filename, document);
    }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to