poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 49254] New: CellUtil.setFont fails
Date Wed, 05 May 2010 15:17:58 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=49254

           Summary: CellUtil.setFont fails
           Product: POI
           Version: 3.6
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XSSF
        AssignedTo: dev@poi.apache.org
        ReportedBy: thomas.herre@abosco.com


Description:
This bug applies to both XSSF and HSSF:
In a workbook, I create a bold font.
Setting this font to a cell using method CellUtil.setFont fails.
Instead, the font at index 0 is used.

Test Code:

        Workbook workbook = new XSSFWorkbook();
        Sheet sheet = workbook.createSheet();

        Row row = sheet.createRow(0);
        Cell cell = row.createCell(0);
        cell.setCellValue("TestCell");

        Font font = workbook.createFont();
        font.setBoldweight(Font.BOLDWEIGHT_BOLD);
        font.setFontHeightInPoints((short) 20);

        // This fails
        CellUtil.setFont(cell, workbook, font);
        // Workaround
//        short fontIndex = font.getIndex();
//        CellUtil.setCellStyleProperty(cell, workbook, CellUtil.FONT,
Short.valueOf(fontIndex));

        workbook.write(new FileOutputStream(new File("test-font.xlsx")));

Evaluation:
CellUtil.setFont calls method setCellStyleProperty and passes-in a Font object
as parameter "propertyValue". It fails a find a style that it can reuse and
creates a new one. Then it calls setFormatProperties which in turn looks up the
font using method getShort. Tha map passed-in contains almost only Short object
as values, but a Font object for property "font". Thus it returns the default
value 0. 

Workaround:
Avoid method CellUtil.setFont and use the workaround (as commented-out in the 
above test code).

-- 
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: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Mime
View raw message