You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Alexander Galloway <ga...@nyu.edu> on 2009/05/20 00:02:14 UTC
CharacterProperties being inconsistently applied
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: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: CharacterProperties being inconsistently applied
Posted by Nick Burch <ni...@torchbox.com>.
On Tue, 19 May 2009, Alexander Galloway wrote:
> 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.
Unfortunately HWPF is in need of some love, but no-one so far has had the
time to give it the work it needs :(
With your test, it'd be interesting to know:
* if you read back the stylings, are they correct then?
* if you save the file, open it again in poi, and check the stylings
correct?
That should at least help figure out if the problem is with how we encode
the character properties, or with hwpf and word doing things differently
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org