From 1a68cc6a2ebd96731cd5269841cd3411240868c9 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Thu, 30 Apr 2015 11:54:13 +0000 Subject: [PATCH] Add verifying testcase for Bug 57423 and Bug 55752, both are still not solved, though. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1676965 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xssf/usermodel/TestUnfixedBugs.java | 169 +++++++++++++++++- test-data/spreadsheet/57423.xlsx | Bin 0 -> 9429 bytes 2 files changed, 167 insertions(+), 2 deletions(-) create mode 100644 test-data/spreadsheet/57423.xlsx diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java index 0e5864b365..b40c4ac1ea 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java @@ -17,7 +17,11 @@ package org.apache.poi.xssf.usermodel; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStream; import java.nio.charset.Charset; import java.util.Calendar; import java.util.Date; @@ -27,6 +31,7 @@ import junit.framework.TestCase; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.DataFormatter; import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.ss.usermodel.FormulaError; @@ -34,10 +39,14 @@ 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.ss.util.CellRangeAddress; +import org.apache.poi.ss.util.CellUtil; +import org.apache.poi.ss.util.RegionUtil; import org.apache.poi.xssf.SXSSFITestDataProvider; import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.junit.Test; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow; /** * @author centic @@ -251,7 +260,7 @@ public final class TestUnfixedBugs extends TestCase { * @param row 0-based * @param column 0-based */ - void setCellFormula(Sheet sheet, int row, int column, String formula) { + private void setCellFormula(Sheet sheet, int row, int column, String formula) { Row r = sheet.getRow(row); if (r == null) { r = sheet.createRow(row); @@ -268,7 +277,163 @@ public final class TestUnfixedBugs extends TestCase { * @param rowNo 0-based * @param column 0-based */ - Cell getCell(Sheet sheet, int rowNo, int column) { + private Cell getCell(Sheet sheet, int rowNo, int column) { return sheet.getRow(rowNo).getCell(column); } + + @Test + public void testBug55752() throws IOException { + Workbook wb = new XSSFWorkbook(); + try { + Sheet sheet = wb.createSheet("test"); + + for (int i = 0; i < 4; i++) { + Row row = sheet.createRow(i); + for (int j = 0; j < 2; j++) { + Cell cell = row.createCell(j); + cell.setCellStyle(wb.createCellStyle()); + } + } + + // set content + Row row1 = sheet.getRow(0); + row1.getCell(0).setCellValue("AAA"); + Row row2 = sheet.getRow(1); + row2.getCell(0).setCellValue("BBB"); + Row row3 = sheet.getRow(2); + row3.getCell(0).setCellValue("CCC"); + Row row4 = sheet.getRow(3); + row4.getCell(0).setCellValue("DDD"); + + // merge cells + CellRangeAddress range1 = new CellRangeAddress(0, 0, 0, 1); + sheet.addMergedRegion(range1); + CellRangeAddress range2 = new CellRangeAddress(1, 1, 0, 1); + sheet.addMergedRegion(range2); + CellRangeAddress range3 = new CellRangeAddress(2, 2, 0, 1); + sheet.addMergedRegion(range3); + assertEquals(0, range3.getFirstColumn()); + assertEquals(1, range3.getLastColumn()); + assertEquals(2, range3.getLastRow()); + CellRangeAddress range4 = new CellRangeAddress(3, 3, 0, 1); + sheet.addMergedRegion(range4); + + // set border + RegionUtil.setBorderBottom(CellStyle.BORDER_THIN, range1, sheet, wb); + + row2.getCell(0).getCellStyle().setBorderBottom(CellStyle.BORDER_THIN); + row2.getCell(1).getCellStyle().setBorderBottom(CellStyle.BORDER_THIN); + + Cell cell0 = CellUtil.getCell(row3, 0); + CellUtil.setCellStyleProperty(cell0, wb, CellUtil.BORDER_BOTTOM, CellStyle.BORDER_THIN); + Cell cell1 = CellUtil.getCell(row3, 1); + CellUtil.setCellStyleProperty(cell1, wb, CellUtil.BORDER_BOTTOM, CellStyle.BORDER_THIN); + + RegionUtil.setBorderBottom(CellStyle.BORDER_THIN, range4, sheet, wb); + + // write to file + OutputStream stream = new FileOutputStream(new File("C:/temp/55752.xlsx")); + try { + wb.write(stream); + } finally { + stream.close(); + } + } finally { + wb.close(); + } + } + + @Test + public void test57423() throws IOException { + Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57423.xlsx"); + + Sheet testSheet = wb.getSheetAt(0); + + // row shift (negative or positive) causes corrupted output xlsx file when the shift value is bigger + // than the number of rows being shifted + // Excel 2010 on opening the output file says: + // "Excel found unreadable content" and offers recovering the file by removing the unreadable content + // This can be observed in cases like the following: + // negative shift of 1 row by less than -1 + // negative shift of 2 rows by less than -2 + // positive shift of 1 row by 2 or more + // positive shift of 2 rows by 3 or more + + //testSheet.shiftRows(4, 5, -3); + testSheet.shiftRows(10, 10, 2); + + checkRows57423(testSheet); + + Workbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(wb); + + /*FileOutputStream stream = new FileOutputStream("C:\\temp\\57423.xlsx"); + try { + wb.write(stream); + } finally { + stream.close(); + }*/ + + wb.close(); + + checkRows57423(wbBack.getSheetAt(0)); + + wbBack.close(); + } + + private void checkRows57423(Sheet testSheet) throws IOException { + checkRow57423(testSheet, 0, "0"); + checkRow57423(testSheet, 1, "1"); + checkRow57423(testSheet, 2, "2"); + checkRow57423(testSheet, 3, "3"); + checkRow57423(testSheet, 4, "4"); + checkRow57423(testSheet, 5, "5"); + checkRow57423(testSheet, 6, "6"); + checkRow57423(testSheet, 7, "7"); + checkRow57423(testSheet, 8, "8"); + checkRow57423(testSheet, 9, "9"); + + assertNull("Row number 10 should be gone after the shift", + testSheet.getRow(10)); + + checkRow57423(testSheet, 11, "11"); + checkRow57423(testSheet, 12, "10"); + checkRow57423(testSheet, 13, "13"); + checkRow57423(testSheet, 14, "14"); + checkRow57423(testSheet, 15, "15"); + checkRow57423(testSheet, 16, "16"); + checkRow57423(testSheet, 17, "17"); + checkRow57423(testSheet, 18, "18"); + + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + try { + ((XSSFSheet)testSheet).write(stream); + } finally { + stream.close(); + } + + // verify that the resulting XML has the rows in correct order as required by Excel + String xml = new String(stream.toByteArray()); + int posR12 = xml.indexOf("yM06_*HTm!)+0RjZK;O@Z#BxrEg zA@G~s_x5F%-S6)oc<-Kb?>&9`*5}-=u1{5WRcorC+yes80O$Y!fDV8f`|1pW1OWKl z0{{pC=*Wh$PL6Jtj&3G8FP$x47;|_z*wg0RLuPpgKt_E3zw5tP10NCw9NW3@<NS?qIwroYIg(R`2ivQ#!BVj>30e)6puH1cyPC=7&ocOZ zpR}+F1(r|Ha-ByQ&62ht8(ZC{I!3*)8e(qJ8^%Uw(x?{!BcYOojS1oTwOMH z?Om_F$$8o20oYfpIS|5KCh*2H&x}6A`10c8&%8E8kxpY8y?o*xa*^1BklvcyG3RxZ zdOlkp%BVb2L+oy9Rh7EFW0J^Q(RX6oI&cHouhS#%N**yD?K&>;HRpRe#V`oh`%5L+ zDw1d>hCL1oY0Y3#_&jhiBz_o|8T|B$(&br%9d4I6Rg15fvjXG$p2{vE4Pr7e`05eK zKiLOb{h*5iV$KN>_JN0(c!YiY*)k$QeFz2tn-~u9lJ>uZZ6br>mC^B=X>s$#(=YNX zwq}xcVQ2d#*F6c#hj`V`HS{N~%gc6bT zx?8}g$3fvY!}C$rs0H|ZkoHrbbf056872cNPa7vlPt!%lv8Cj!LWS;Va8^Eb+_5y7 zZDYof@DuM;&He}OvfJ-0K2&5evjO?1o=H({Lq#rFH)m%#ujr(Ftc1eIzRL3j-hNSN zl)rq$B%$qfXqbu%pU`^b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