https://issues.apache.org/bugzilla/show_bug.cgi?id=44680

           Summary: autoSizeColumn dislike HSSFFont
           Product: POI
           Version: 3.0
          Platform: PC
               URL: http://article.gmane.org/gmane.comp.jakarta.poi.user/102
                    47
        OS/Version: Windows XP
            Status: NEW
          Severity: normal
          Priority: P2
         Component: HSSF
        AssignedTo: dev@poi.apache.org
        ReportedBy: [EMAIL PROTECTED]


I'm working with POI 3.0.2-FINAL, and I met a stressful problem when trying to
autosize a column where there's a FONT apply to. I obtain that ugly exception:

java.lang.ClassCastException: org.apache.poi.hssf.record.StyleRecord
    at org.apache.poi.hssf.model.Workbook.getExFormatAt(Workbook.java:665)
    at org.apache.poi.hssf.usermodel.HSSFCell.getCellStyle(HSSFCell.java:896)
    at
org.apache.poi.hssf.usermodel.HSSFSheet.autoSizeColumn(HSSFSheet.java:1690)

Here an abstract of the code producing that stack:

private static HSSFCellStyle _BOLD_STYLE = null;
    private static HSSFFont _BOLD_FONT = null;

    private HSSFCellStyle getBoldStyle() {
        if (null == _BOLD_STYLE) {
            _BOLD_STYLE = _wb.createCellStyle();
            _BOLD_STYLE.setFont(getBoldFont());
        }
        return _BOLD_STYLE;
    }

    private HSSFFont getBoldFont() {
        if (null == _BOLD_FONT) {
            _BOLD_FONT = _wb.createFont();
            _BOLD_FONT.setFontHeightInPoints((short)10);
            _BOLD_FONT.setColor(HSSFFont.COLOR_NORMAL);
            _BOLD_FONT.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        }
        return _BOLD_FONT;
    }

Then during usage:

HSSFCell c = null;
        _curCellIndex = -1;
        r = _sheet.createRow(++_curRowIndex);
        c = r.createCell(++_curCellIndex);
        final HSSFRichTextString ref = new HSSFRichTextString("Référence");
        c.setCellValue(ref);
        c.setCellStyle(getBoldStyle());

This is done somthing like 13times for "headers" in my sheet.

And once the page is created, I call this:

private void layout() {
        _sheet.setColumnWidth((short)0, (short)2500);
        _sheet.setColumnWidth((short)1, (short)2500);

        for (short i = 2; i < 30; ++i) {
            _sheet.autoSizeColumn(i);
        }
    }

Then autoSizeColumn fire that strange exception.
This example is run under jdk_1.4.2_11, but the dev environnement is jdk1.6.0
(don't think it touch that).


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to