You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Jaroslav Lunda <ja...@crcdata.cz> on 2011/03/11 15:22:35 UTC

hssf and multiple colors per cell

Hi, if one has cell with some multicolored text (each word different color) - it is possible to obtain all of these colors using hssf?
It seems to me that only one color can be obtained per font, one font per style and one style per cell.
Is there any other way to do this?

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


Re: hssf and multiple colors per cell

Posted by Mark Beardsley <ma...@tiscali.co.uk>.
Only if the cell contains text, if it contains a number or a date for
example, then it is not possible to do this using the API. The key is that
you need to recover a rich text string object from the cell - and the api
will throw an exception if you call the relevenat method on a numeric cell
for example. That object will contain a series of what are referred to as
formatting runs and associated with each will be a font object. That font
object contains information such as name, size, colour, eyc. Currently, on
another thread, we are working toward a solution - there are a couple of
wrinkles to iron out still - that allows us to detect whether the font is
superscripted or not. If you keep an eye on that, the same sort of technique
will allow you to detect colour; but it is important to emphasise that this
will work only for cells that contain a string, or that, more accurately,
have the type Cell.CELL_TYPE_STRING.

Yours

Mark B

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/hssf-and-multiple-colors-per-cell-tp3425176p3455961.html
Sent from the POI - User mailing list archive at Nabble.com.

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


Re: hssf and multiple colors per cell

Posted by Yegor Kozlov <ye...@dinom.ru>.
        HSSFRichTextString str =
workbook.getSheetAt(1).getRow(3).getCell(0).getRichStringCellValue();
        for(int i = 0; i < str.numFormattingRuns(); i++){
            short fontIndex = str.getFontOfFormattingRun(i);
            HSSFFont font = wb.getFontAt(fontIndex);
            int colorIndex = font.getColor();
            HSSFColor color = HSSFColor.getIndexHash().get(colorIndex);
            System.out.println(color);
        }

Regards,
Yegor

On Fri, Mar 11, 2011 at 5:22 PM, Jaroslav Lunda
<ja...@crcdata.cz> wrote:
> Hi, if one has cell with some multicolored text (each word different color) - it is possible to obtain all of these colors using hssf?
> It seems to me that only one color can be obtained per font, one font per style and one style per cell.
> Is there any other way to do this?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

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