https://bz.apache.org/bugzilla/show_bug.cgi?id=61048

            Bug ID: 61048
           Summary: Newlines in cells not rendering with SXSSF
           Product: POI
           Version: 3.15-FINAL
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: SXSSF
          Assignee: dev@poi.apache.org
          Reporter: mich...@hurts.ca
  Target Milestone: ---

Created attachment 34957
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=34957&action=edit
XSSF - newline rendered correctly

Using the guide here:

http://poi.apache.org/spreadsheet/quick-guide.html#NewLinesInCells

I was able to produce a cell with an embedded newline in an XSSF. It looks
correct in Excel for Mac.

Using the same code but swapping out XSSF for SXSSF, the newline is rendered as
a regular space (in Excel for Mac, at least).

SXSSF serializes the newline as "
" in the worksheet XML. I found by
manually changing this to "
" or "
" (hex/decimal encodings of carriage
return), and rezipping the xlsx, the newline was correctly rendered.

Sample code:

public class NewlineTest {
    @Test
    public void doitStreaming() throws Exception {
        Workbook workbook = new SXSSFWorkbook();
        //Workbook workbook = new XSSFWorkbook();

        CellStyle commentStyle = workbook.createCellStyle();
        commentStyle.setVerticalAlignment(VerticalAlignment.TOP);
        commentStyle.setWrapText(true);

        Sheet sheet = workbook.createSheet("blah");

        Row row = sheet.createRow(0);
        Cell cell = row.createCell(0);
        cell.setCellStyle(commentStyle);
        cell.setCellValue("one two three four\nnewline six seven eight");

        workbook.write(new FileOutputStream("/tmp/sxssf.xlsx"));

        workbook.dispose();
    }
}

I'm attaching the output from XSSF (xssf.xlsx), SXSSF (sxssf.xlsx), and the
manually adjusted file (sxssf_with_cr.xlsx).

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@poi.apache.org
For additional commands, e-mail: dev-h...@poi.apache.org

Reply via email to