@Override
@Test
- public void testShiftRowBreaks() {
+ public void testShiftRowBreaks() {
// disabled test from superclass
// TODO - support shifting of page breaks
}
@Test
- public void testBug54524() throws IOException {
+ public void testBug54524() throws IOException {
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("54524.xlsx");
XSSFSheet sheet = workbook.getSheetAt(0);
- sheet.shiftRows(3, 5, -1);
+ sheet.shiftRows(3, 5, -1);
Cell cell = CellUtil.getCell(sheet.getRow(1), 0);
- assertEquals(1.0, cell.getNumericCellValue(), 0);
- cell = CellUtil.getCell(sheet.getRow(2), 0);
- assertEquals("SUM(A2:A2)", cell.getCellFormula());
- cell = CellUtil.getCell(sheet.getRow(3), 0);
- assertEquals("X", cell.getStringCellValue());
- workbook.close();
- }
+ assertEquals(1.0, cell.getNumericCellValue(), 0);
+ cell = CellUtil.getCell(sheet.getRow(2), 0);
+ assertEquals("SUM(A2:A2)", cell.getCellFormula());
+ cell = CellUtil.getCell(sheet.getRow(3), 0);
+ assertEquals("X", cell.getStringCellValue());
+ workbook.close();
+ }
@Test
- public void testBug53798() throws IOException {
- // NOTE that for HSSF (.xls) negative shifts combined with positive ones do work as expected
- Workbook wb = XSSFTestDataSamples.openSampleWorkbook("53798.xlsx");
-
- Sheet testSheet = wb.getSheetAt(0);
- // 1) corrupted xlsx (unreadable data in the first row of a shifted group) already comes about
- // when shifted by less than -1 negative amount (try -2)
- testSheet.shiftRows(3, 3, -2);
-
- Row newRow = null; Cell newCell = null;
- // 2) attempt to create a new row IN PLACE of a removed row by a negative shift causes corrupted
- // xlsx file with unreadable data in the negative shifted row.
- // NOTE it's ok to create any other row.
- newRow = testSheet.createRow(3);
- newCell = newRow.createCell(0);
- newCell.setCellValue("new Cell in row "+newRow.getRowNum());
-
- // 3) once a negative shift has been made any attempt to shift another group of rows
- // (note: outside of previously negative shifted rows) by a POSITIVE amount causes POI exception:
- // org.apache.xmlbeans.impl.values.XmlValueDisconnectedException.
- // NOTE: another negative shift on another group of rows is successful, provided no new rows in
- // place of previously shifted rows were attempted to be created as explained above.
-
- // -- CHANGE the shift to positive once the behaviour of the above has been tested
- testSheet.shiftRows(6, 7, 1);
-
- Workbook read = XSSFTestDataSamples.writeOutAndReadBack(wb);
- wb.close();
- assertNotNull(read);
-
- Sheet readSheet = read.getSheetAt(0);
- verifyCellContent(readSheet, 0, "0.0");
- verifyCellContent(readSheet, 1, "3.0");
- verifyCellContent(readSheet, 2, "2.0");
- verifyCellContent(readSheet, 3, "new Cell in row 3");
- verifyCellContent(readSheet, 4, "4.0");
- verifyCellContent(readSheet, 5, "5.0");
- verifyCellContent(readSheet, 6, null);
- verifyCellContent(readSheet, 7, "6.0");
- verifyCellContent(readSheet, 8, "7.0");
- read.close();
- }
-
- private void verifyCellContent(Sheet readSheet, int row, String expect) {
- Row readRow = readSheet.getRow(row);
- if(expect == null) {
- assertNull(readRow);
- return;
- }
- Cell readCell = readRow.getCell(0);
- if(readCell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
- assertEquals(expect, Double.toString(readCell.getNumericCellValue()));
- } else {
- assertEquals(expect, readCell.getStringCellValue());
- }
- }
-
- @Test
- public void testBug53798a() throws IOException {
- Workbook wb = XSSFTestDataSamples.openSampleWorkbook("53798.xlsx");
-
- Sheet testSheet = wb.getSheetAt(0);
- testSheet.shiftRows(3, 3, -1);
+ public void testBug53798() throws IOException {
+ // NOTE that for HSSF (.xls) negative shifts combined with positive ones do work as expected
+ Workbook wb = XSSFTestDataSamples.openSampleWorkbook("53798.xlsx");
+
+ Sheet testSheet = wb.getSheetAt(0);
+ // 1) corrupted xlsx (unreadable data in the first row of a shifted group) already comes about
+ // when shifted by less than -1 negative amount (try -2)
+ testSheet.shiftRows(3, 3, -2);
+
+ Row newRow = null; Cell newCell = null;
+ // 2) attempt to create a new row IN PLACE of a removed row by a negative shift causes corrupted
+ // xlsx file with unreadable data in the negative shifted row.
+ // NOTE it's ok to create any other row.
+ newRow = testSheet.createRow(3);
+ newCell = newRow.createCell(0);
+ newCell.setCellValue("new Cell in row "+newRow.getRowNum());
+
+ // 3) once a negative shift has been made any attempt to shift another group of rows
+ // (note: outside of previously negative shifted rows) by a POSITIVE amount causes POI exception:
+ // org.apache.xmlbeans.impl.values.XmlValueDisconnectedException.
+ // NOTE: another negative shift on another group of rows is successful, provided no new rows in
+ // place of previously shifted rows were attempted to be created as explained above.
+
+ // -- CHANGE the shift to positive once the behaviour of the above has been tested
+ testSheet.shiftRows(6, 7, 1);
+
+ Workbook read = XSSFTestDataSamples.writeOutAndReadBack(wb);
+ wb.close();
+ assertNotNull(read);
+
+ Sheet readSheet = read.getSheetAt(0);
+ verifyCellContent(readSheet, 0, "0.0");
+ verifyCellContent(readSheet, 1, "3.0");
+ verifyCellContent(readSheet, 2, "2.0");
+ verifyCellContent(readSheet, 3, "new Cell in row 3");
+ verifyCellContent(readSheet, 4, "4.0");
+ verifyCellContent(readSheet, 5, "5.0");
+ verifyCellContent(readSheet, 6, null);
+ verifyCellContent(readSheet, 7, "6.0");
+ verifyCellContent(readSheet, 8, "7.0");
+ read.close();
+ }
+
+ private void verifyCellContent(Sheet readSheet, int row, String expect) {
+ Row readRow = readSheet.getRow(row);
+ if(expect == null) {
+ assertNull(readRow);
+ return;
+ }
+ Cell readCell = readRow.getCell(0);
+ if(readCell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
+ assertEquals(expect, Double.toString(readCell.getNumericCellValue()));
+ } else {
+ assertEquals(expect, readCell.getStringCellValue());
+ }
+ }
+
+ @Test
+ public void testBug53798a() throws IOException {
+ Workbook wb = XSSFTestDataSamples.openSampleWorkbook("53798.xlsx");
+
+ Sheet testSheet = wb.getSheetAt(0);
+ testSheet.shiftRows(3, 3, -1);
for (Row r : testSheet) {
- r.getRowNum();
+ r.getRowNum();
}
- testSheet.shiftRows(6, 6, 1);
-
- Workbook read = XSSFTestDataSamples.writeOutAndReadBack(wb);
- wb.close();
- assertNotNull(read);
-
- Sheet readSheet = read.getSheetAt(0);
- verifyCellContent(readSheet, 0, "0.0");
- verifyCellContent(readSheet, 1, "1.0");
- verifyCellContent(readSheet, 2, "3.0");
- verifyCellContent(readSheet, 3, null);
- verifyCellContent(readSheet, 4, "4.0");
- verifyCellContent(readSheet, 5, "5.0");
- verifyCellContent(readSheet, 6, null);
- verifyCellContent(readSheet, 7, "6.0");
- verifyCellContent(readSheet, 8, "8.0");
- read.close();
- }
-
- @Test
- public void testBug56017() throws IOException {
- Workbook wb = XSSFTestDataSamples.openSampleWorkbook("56017.xlsx");
+ testSheet.shiftRows(6, 6, 1);
+
+ Workbook read = XSSFTestDataSamples.writeOutAndReadBack(wb);
+ wb.close();
+ assertNotNull(read);
+
+ Sheet readSheet = read.getSheetAt(0);
+ verifyCellContent(readSheet, 0, "0.0");
+ verifyCellContent(readSheet, 1, "1.0");
+ verifyCellContent(readSheet, 2, "3.0");
+ verifyCellContent(readSheet, 3, null);
+ verifyCellContent(readSheet, 4, "4.0");
+ verifyCellContent(readSheet, 5, "5.0");
+ verifyCellContent(readSheet, 6, null);
+ verifyCellContent(readSheet, 7, "6.0");
+ verifyCellContent(readSheet, 8, "8.0");
+ read.close();
+ }
+
+ @Test
+ public void testBug56017() throws IOException {
+ Workbook wb = XSSFTestDataSamples.openSampleWorkbook("56017.xlsx");
Sheet sheet = wb.getSheetAt(0);
assertEquals("Amdocs", comment.getAuthor());
assertEquals("Amdocs:\ntest\n", comment.getString().getString());
wbBack.close();
- }
+ }
- @Test
+ @Test
public void test57171() throws IOException {
- Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57171_57163_57165.xlsx");
+ Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57171_57163_57165.xlsx");
assertEquals(5, wb.getActiveSheetIndex());
removeAllSheetsBut(5, wb); // 5 is the active / selected sheet
assertEquals(0, wb.getActiveSheetIndex());
wbRead.close();
}
- @Test
+ @Test
public void test57163() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57171_57163_57165.xlsx");
assertEquals(5, wb.getActiveSheetIndex());
wb.close();
}
- @Test
+ @Test
public void testSetSheetOrderAndAdjustActiveSheet() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57171_57163_57165.xlsx");
wb.close();
}
- @Test
+ @Test
public void testRemoveSheetAndAdjustActiveSheet() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57171_57163_57165.xlsx");
wb.close();
}
- @Test
+ @Test
public void test57165() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57171_57163_57165.xlsx");
assertEquals(5, wb.getActiveSheetIndex());
@Test
public final void testShiftRow() throws IOException {
Workbook wb = _testDataProvider.createWorkbook();
- Sheet s = wb.createSheet();
+ Sheet s = wb.createSheet();
s.createRow(0).createCell(0).setCellValue("TEST1");
s.createRow(3).createCell(0).setCellValue("TEST2");
s.shiftRows(0,4,1);
@Test
public final void testActiveCell() throws IOException {
Workbook wb = _testDataProvider.createWorkbook();
- Sheet s = wb.createSheet();
+ Sheet s = wb.createSheet();
s.createRow(0).createCell(0).setCellValue("TEST1");
s.createRow(3).createCell(0).setCellValue("TEST2");
@Test
public void testShiftRowBreaks() throws IOException { // TODO - enable XSSF test
Workbook wb = _testDataProvider.createWorkbook();
- Sheet s = wb.createSheet();
+ Sheet s = wb.createSheet();
Row row = s.createRow(4);
row.createCell(0).setCellValue("test");
s.setRowBreak(4);
// TODO: it seems HSSFSheet does not correctly remove comments from rows that are overwritten
// by shifting rows...
if(!(wb2 instanceof HSSFWorkbook)) {
- assertEquals(2, sheet.getLastRowNum());
-
- // Verify comments are in the position expected
- assertNull("Had: " + (sheet.getCellComment(new CellAddress(0,0)) == null ? "null" : sheet.getCellComment(new CellAddress(0,0)).getString()),
- sheet.getCellComment(new CellAddress(0,0)));
- assertNotNull(sheet.getCellComment(new CellAddress(1,0)));
- assertNotNull(sheet.getCellComment(new CellAddress(2,0)));
+ assertEquals(2, sheet.getLastRowNum());
+
+ // Verify comments are in the position expected
+ assertNull("Had: " + (sheet.getCellComment(new CellAddress(0,0)) == null ? "null" : sheet.getCellComment(new CellAddress(0,0)).getString()),
+ sheet.getCellComment(new CellAddress(0,0)));
+ assertNotNull(sheet.getCellComment(new CellAddress(1,0)));
+ assertNotNull(sheet.getCellComment(new CellAddress(2,0)));
}
comment1 = sheet.getCellComment(new CellAddress(1,0)).getString().getString();
@Test
public final void testShiftWithMergedRegions() throws IOException {
Workbook wb = _testDataProvider.createWorkbook();
- Sheet sheet = wb.createSheet();
+ Sheet sheet = wb.createSheet();
Row row = sheet.createRow(0);
row.createCell(0).setCellValue(1.1);
row.createCell(1).setCellValue(2.2);
}
@Test
- public void testBug55280() throws IOException {
+ public void testBug55280() throws IOException {
Workbook w = _testDataProvider.createWorkbook();
Sheet s = w.createSheet();
for (int row = 0; row < 5000; ++row)
s.shiftRows(0, 4999, 1); // takes a long time...
w.close();
- }
+ }
@Test
public void test47169() throws IOException {