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: [email protected]
        ReportedBy: [email protected]


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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to