nissl-lab / npoi

a .NET library that can read/write Office formats without Microsoft Office installed. No COM+, no interop.
Apache License 2.0
5.74k stars 1.43k forks source link

Inconsistent new lines in worksheets #1401

Closed lechu445 closed 2 months ago

lechu445 commented 3 months ago

NPOI Version

2.7.1

File Type

Upload the Excel File

Please attach your original Excel File to help us reproduce the issue

xssf.xlsx sxssf.xlsx

Reproduce Steps

using NPOI.XSSF.Streaming;
using NPOI.XSSF.UserModel;

using (var fileStream = File.OpenWrite("xssf.xlsx"))
using (var workbook = new XSSFWorkbook())
{
    var sheet = workbook.CreateSheet();
    var row = sheet.CreateRow(0);
    var cell = row.CreateCell(0);

    cell.SetCellValue("first\r\nsecond");

    workbook.Write(fileStream);
}

using (var fileStream = File.OpenWrite("sxssf.xlsx"))
using (var workbook = new SXSSFWorkbook())
{
    var sheet = workbook.CreateSheet();
    var row = sheet.CreateRow(0);
    var cell = row.CreateCell(0);

    cell.SetCellValue("first\r\nsecond");

    workbook.Write(fileStream);
}

Issue Description

There is an inconsistency between behavior of XSSFWorkbook and SXSSFWorkbook. When \r\n is written SXSSF incorrectly writes two new lines, XSSF writes only one (and it's the correct behavior).

In XSSF the cell contains:

first
second

In SXSSF the cell contains:

first

second

It looks, the SXSSF incorrectly contain two new lines instead of only one, same as for XSSF.

wuzxc1230123 commented 3 months ago

ASCII Erro ,need fix