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 48877] New: XSSFRichTextString: applyFont removes line break
Date Tue, 09 Mar 2010 12:50:37 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=48877

           Summary: XSSFRichTextString: applyFont removes line break
           Product: POI
           Version: 3.6
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XSSF
        AssignedTo: dev@poi.apache.org
        ReportedBy: sm01@mitzis-home.de


If you use an XSSFWorkbook together with a RichTextString, that applies a font
to a string containing a new line char ("\n"), the line-break is ignored. 
Here is a slightly modified code sample of the "Quick-Guide - Using newlines in
cells" http://jakarta.apache.org/poi/hssf/quick-guide.html#NewLinesInCells:

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

        Font font1 = wb.createFont();
        font1.setColor((short) 20);

        Row row = sheet.createRow(2);
        Cell cell = row.createCell(2);

        RichTextString richTextString =
wb.getCreationHelper().createRichTextString("Use \n with word wrap on to create
a new line");
        richTextString.applyFont(0, 3, font1);
        cell.setCellValue(richTextString);

        //to enable newlines you need set a cell styles with wrap=true
        CellStyle cs = wb.createCellStyle();
        cs.setWrapText(true);
        cell.setCellStyle(cs);

        //increase row height to accomodate two lines of text
        row.setHeightInPoints((2*sheet.getDefaultRowHeightInPoints()));

        //adjust column width to fit the content
        //sheet.autoSizeColumn((short)2);

        FileOutputStream fileOut = new FileOutputStream("ooxml-newlines.xlsx");
        wb.write(fileOut);
        fileOut.close();

-- 
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