Skip to content

Commit bac4ad5

Browse files
committed
Update StreamingSheetTest.java
1 parent a34b1fd commit bac4ad5

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/test/java/com/github/pjfanning/xlsx/StreamingSheetTest.java

+56
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.apache.poi.ss.util.CellAddress;
88
import org.apache.poi.ss.util.CellRangeAddress;
99
import org.apache.poi.ss.util.PaneInformation;
10+
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
1011
import org.apache.poi.xssf.usermodel.XSSFHyperlink;
1112
import org.apache.poi.xssf.usermodel.XSSFSheet;
1213
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@@ -450,4 +451,59 @@ public void testRowStyle() throws IOException {
450451
assertTrue(row1.isFormatted());
451452
}
452453
}
454+
455+
@Test
456+
public void testCellWithLineBreak() throws IOException {
457+
final String testValue = "1\n2\r\n3";
458+
try (
459+
XSSFWorkbook xssfWorkbook = new XSSFWorkbook();
460+
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
461+
) {
462+
Sheet xssfSheet = xssfWorkbook.createSheet();
463+
xssfSheet.createRow(0).createCell(0).setCellValue(testValue);
464+
465+
xssfWorkbook.write(bos);
466+
467+
try (Workbook wb = StreamingReader.builder().open(bos.toInputStream())) {
468+
Sheet sheet = wb.getSheetAt(0);
469+
Iterator<Row> rowIterator = sheet.rowIterator();
470+
if (rowIterator.hasNext()) {
471+
Row row = rowIterator.next();
472+
if (row.getRowNum() == 0) {
473+
Cell cell0 = row.getCell(0);
474+
assertNotNull(cell0);
475+
assertEquals(testValue, cell0.getStringCellValue());
476+
}
477+
}
478+
}
479+
}
480+
}
481+
482+
@Test
483+
public void testCellWithLineBreakNoSharedStrings() throws IOException {
484+
//SXSSFWorkbook does not use SharedStrings by default
485+
final String testValue = "1\n2\r\n3";
486+
try (
487+
SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook();
488+
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
489+
) {
490+
Sheet xssfSheet = sxssfWorkbook.createSheet();
491+
xssfSheet.createRow(0).createCell(0).setCellValue(testValue);
492+
493+
sxssfWorkbook.write(bos);
494+
495+
try (Workbook wb = StreamingReader.builder().open(bos.toInputStream())) {
496+
Sheet sheet = wb.getSheetAt(0);
497+
Iterator<Row> rowIterator = sheet.rowIterator();
498+
if (rowIterator.hasNext()) {
499+
Row row = rowIterator.next();
500+
if (row.getRowNum() == 0) {
501+
Cell cell0 = row.getCell(0);
502+
assertNotNull(cell0);
503+
assertEquals(testValue, cell0.getStringCellValue());
504+
}
505+
}
506+
}
507+
}
508+
}
453509
}

0 commit comments

Comments
 (0)