diff options
author | Dominik Stadler <centic@apache.org> | 2023-05-14 07:47:16 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2023-05-14 07:47:16 +0000 |
commit | 720027879fd6c80abe4c133cfa2496647060194f (patch) | |
tree | e4e78a651c0c3e2f58499243a0273f53dd384b0d /poi-ooxml | |
parent | a647cc97e74c9a236e021b79bb53c3de6d30045c (diff) | |
download | poi-720027879fd6c80abe4c133cfa2496647060194f.tar.gz poi-720027879fd6c80abe4c133cfa2496647060194f.zip |
Bug 66598: Fix invalid loop-condition when cleaning up CTCells
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1909808 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml')
-rw-r--r-- | poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFRow.java | 2 | ||||
-rw-r--r-- | poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFRow.java | 52 |
2 files changed, 52 insertions, 2 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFRow.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFRow.java index 8203f6d6c9..bceb6cddfa 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFRow.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFRow.java @@ -608,7 +608,7 @@ public class XSSFRow implements Row, Comparable<XSSFRow> { } // remove any remaining illegal references in _rows.cArray - while(cArrayOrig.length > _cells.size()) { + while(_row.getCArray().length > _cells.size()) { _row.removeC(_cells.size()); } } diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFRow.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFRow.java index b1b7688323..7fda7438ef 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFRow.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFRow.java @@ -21,12 +21,22 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertSame; +import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.OutputStream; import org.apache.poi.common.usermodel.HyperlinkType; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.tests.usermodel.BaseTestXRow; -import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellCopyContext; +import org.apache.poi.ss.usermodel.CellCopyPolicy; +import org.apache.poi.ss.usermodel.CellType; +import org.apache.poi.ss.usermodel.Hyperlink; +import org.apache.poi.ss.usermodel.RichTextString; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.XSSFTestDataSamples; import org.junit.jupiter.api.Test; @@ -426,4 +436,44 @@ public final class TestXSSFRow extends BaseTestXRow { XSSFWorkbook wb3 = XSSFTestDataSamples.writeOutAndReadBack(wb1); assertEquals(CellType.BLANK, wb3.getSheet("Sheet1").getRow(0).getCell(1).getCellType(), "Cell should be blank"); } + + @Test + void createHeaderOnce() throws IOException { + Workbook wb = new XSSFWorkbook(); + fillData(1, wb.createSheet("sheet123")); + writeToFile(wb); + } + + @Test + void createHeaderTwice() throws IOException { + Workbook wb = new XSSFWorkbook(); + fillData(0, wb.createSheet("sheet123")); + writeToFile(wb); + } + + @Test + void createHeaderThreeTimes() throws IOException { + Workbook wb = new XSSFWorkbook(); + Sheet sheet = wb.createSheet("sheet123"); + fillData(1, sheet); + fillData(0, sheet); + fillData(0, sheet); + writeToFile(wb); + } + + private void fillData(int startAtRow, Sheet sheet) { + Row header = sheet.createRow(0); + for (int rownum = startAtRow; rownum < 2; rownum++) { + header.createCell(0).setCellValue("a"); + + Row row = sheet.createRow(rownum); + row.createCell(0).setCellValue("a"); + } + } + + private void writeToFile(Workbook wb) throws IOException { + try (OutputStream fileOut = new ByteArrayOutputStream()) { + wb.write(fileOut); + } + } } |