Author: fanningpj
Date: Tue Dec 21 15:16:46 2021
New Revision: 1896247
URL: http://svn.apache.org/viewvc?rev=1896247&view=rev
Log:
[bug-64732] add support for new line escaping when updating table names - test
case
Modified:
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFTable.java
Modified:
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFTable.java
URL:
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFTable.java?rev=1896247&r1=1896246&r2=1896247&view=diff
==============================================================================
---
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFTable.java
(original)
+++
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFTable.java
Tue Dec 21 15:16:46 2021
@@ -34,6 +34,7 @@ import java.util.Locale;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.util.TempFile;
@@ -653,4 +654,58 @@ public final class TestXSSFTable {
final AreaReference area = new AreaReference(upperLeft, lowerRight,
SpreadsheetVersion.EXCEL2007);
return sheet.createTable(area);
}
+
+ @Test
+ void testNamesWithNewLines() throws IOException {
+ try (
+ XSSFWorkbook wb = new XSSFWorkbook();
+ UnsynchronizedByteArrayOutputStream bos = new
UnsynchronizedByteArrayOutputStream()
+ ) {
+ XSSFSheet sheet = wb.createSheet();
+
+ // headers
+ XSSFRow headersRow = sheet.createRow(0);
+ headersRow.createCell(0).setCellValue("Column1");
+ headersRow.createCell(1).setCellValue("Column2");
+
+ // a second row
+ XSSFRow row = sheet.createRow(1);
+ row.createCell(0).setCellValue(1);
+ row.createCell(1).setCellValue(2);
+
+ // create a table
+ AreaReference area = wb.getCreationHelper().createAreaReference(
+ new CellReference(sheet.getRow(0).getCell(0)),
+ new CellReference(sheet.getRow(1).getCell(1))
+ );
+ XSSFTable table = sheet.createTable(area);
+
+ // styling (no problem here)
+ sheet.setColumnWidth(0, 5000);
+ sheet.setColumnWidth(1, 5000);
+ CTTable cttable = table.getCTTable();
+ cttable.addNewTableStyleInfo();
+ XSSFTableStyleInfo style = (XSSFTableStyleInfo) table.getStyle();
+ style.setName("TableStyleMedium6");
+ style.setShowColumnStripes(false);
+ style.setShowRowStripes(true);
+ cttable.addNewAutoFilter().setRef(area.formatAsString());
+ CellStyle cellStyle = wb.createCellStyle();
+ cellStyle.setWrapText(true);
+ headersRow.getCell(0).setCellStyle(cellStyle);
+ headersRow.getCell(0).setCellValue("Column1\nwith a line break");
+
+ wb.write(bos);
+
+ try (XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) {
+ XSSFSheet wb2Sheet = wb2.getSheetAt(0);
+ List<XSSFTable> tables = wb2Sheet.getTables();
+ assertEquals(1, tables.size());
+ XSSFTable wb2Table = tables.get(0);
+ List<XSSFTableColumn> tabColumns = wb2Table.getColumns();
+ assertEquals(2, tabColumns.size());
+ assertEquals("Column1_x000a_with a line break",
tabColumns.get(0).getName());
+ }
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]