Originally posted by Ulf Dittmer:
The following snippet will tell you about the style at each character index:
Originally posted by Ulf Dittmer:
This is another approach that enumerates the formatting runs, but the indices it returns are a bit goofy:
Originally posted by Ulf Dittmer:
I've sent you a private message. You can read it by following the "My Profile" link at the top of the page.
Originally posted by Ulf Dittmer:
and another run that's bold, italics, underline starting at index 17.
[ August 06, 2007: Message edited by: Ulf Dittmer ]
But there does not seem to be any method which will get me the character style.
String text = rts.toString();
for (int i=0; i<rts.length(); i++) {
System.out.println("index = "+i+", char '"+text.charAt(i)+"'");
System.out.println("font # = "+rts.getFontAtIndex(i));
HSSFFont font = wb.getFontAt(rts.getFontAtIndex(i));
System.out.println("bold = "+font.getBoldweight());
System.out.println("italic = "+font.getItalic());
System.out.println("underline = "+font.getUnderline());
System.out.println("strikeout = "+font.getStrikeout());
System.out.println();
}
rts.numFormattingRuns() returns 0, so I never get into the for loop.
Originally posted by Ulf Dittmer:
Short of fixing the bug -if there is one- I don't think this can be solved.
But let me ask again, because I'm still not clear on this from what you write: numFormattingRuns() returns 0 for a cell that contains more than one style, e.g. "bbb iii"? That would be a bug, but I'm not seeing it. Feel free to send me an XLS file that exhibits this behavior.
Originally posted by Thomas Greene:
You are right Ulf. Seems to be my mistake. I might be pointing to the wrong cell.
Although I am getting a value for numFormattingRuns but it is not the correct value. I'll mail you that sheet in a while.
Originally posted by Ulf Dittmer:
So the number of runs returned by is() is one less than the actual number of runs (because the first one is considered the cell style).
Originally posted by Ulf Dittmer:
Maybe the API is modeled after the internal structure of the XLS file format, and that this is how the file format stores it.
The important thing is that it is possible to get at all data even if it's non-obvious how to do so. I'd recommend that you submit improved documentation for the HSSFRichTextString class to the POI folks, so that the next person wondering about this knows what's going on.
But I am still wondering how to get the formatting of the first word in the cell.
Originally posted by Ulf Dittmer:
By using the cell style. See my post starting with "The difference seems to be that there...".
I had described the algorithm to use -no matter how many runs of styled text there are- in the post starting "Maybe that's an artifact if there ...".
BTW, did you see this?
[ August 08, 2007: Message edited by: Ulf Dittmer ]
Water proof donuts! Eat them while reading this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|