Mark Beardsley <markbrdsly <at> tiscali.co.uk> writes:

> 
> What happens if you make a simple change to the sequence of your method
> class, a little like this;
>
> public Workbook createRichTextWorkbook() {
>         Workbook wb = new SXSSFWorkbook();
> 
>         Sheet copySheet = wb.createSheet("TestRT");
>         Row copyRow = copySheet.createRow(0);
>         Cell copyCell = copyRow.createCell(0);
> 
>         XSSFFont font1 = (XSSFFont) wb.createFont();
>         font1.setFontName("Arial");
>         font1.setFontHeightInPoints((short) 12);
>         font1.setBold(true);
>         font1.setColor(new XSSFColor(new java.awt.Color(255, 0, 0)));
> 
>         //create a cell style and assign the first font to it
>         CellStyle style = wb.createCellStyle();
>         style.setFont(font1);
>         copyCell.setCellStyle(style);
> 
>         XSSFFont font2 = (XSSFFont) wb.createFont();
>         font2.setFontName("Arial");
>         font2.setFontHeightInPoints((short)12);
>         font2.setItalic(true);
>         font2.setColor(new XSSFColor(new java.awt.Color(0, 255, 0)));
> 
>         XSSFRichTextString rt = (XSSFRichTextString)
> wb.getCreationHelper().createRichTextString("Hello, World!");
>         rt.applyFont( 6, 13, font2 );
> 
>         copyCell.setCellValue(rt);
> 
>         return wb;
>     }
> 
> I am just wondering if assigning the style to the cell as you did originally
> was taken by POI to indicate that this style should over-ride anything else
> applied to the cells contents. I do not know if this is the case but it
> might be the first place to look for an answer.
> 

First. Nothing happens. In both cases call of 'setCellValue(rt)' is in the last
line of code.
I mean both examples are identical.

Second. Ok, let's simplify our example:
----------------------------------------------

    public Workbook createRichTextWorkbook() {
        Workbook wb = new SXSSFWorkbook();

        Sheet sheet = wb.createSheet("TestRT");
        Row row = sheet.createRow(0);
        Cell cell = row.createCell(0);

        XSSFFont font1 = (XSSFFont) wb.createFont();
        font1.setFontName("Arial");
        font1.setFontHeightInPoints((short) 12);
        font1.setUnderline(FontUnderline.DOUBLE);
        font1.setBold(true);
        font1.setColor(new XSSFColor(new java.awt.Color(255, 0, 0)));

        XSSFFont font2 = (XSSFFont) wb.createFont();
        font2.setFontName("Courier");
        font2.setFontHeightInPoints((short)14);
        font2.setItalic(true);
        font2.setColor(new XSSFColor(new java.awt.Color(0, 0, 255)));

        XSSFRichTextString rt = (XSSFRichTextString)
wb.getCreationHelper().createRichTextString("Hello, World!");
        rt.applyFont( 0, 6, font1 );
        rt.applyFont( 6, rt.getString().length(), font2 );

        cell.setCellValue(rt);

        return wb;
    }

----------------------------------------------

It isn't working for 'SXSSFWorkbook'. A plain text is rendered when the
'SXSSFWorkbook' is used.
But when the 'XSSFWorkbook' is used a rich text is rendered. I mean:

Workbook wb = new XSSFWorkbook();

Thanks,
Marat


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

Reply via email to