From cb54849561ea3c1f99d11097de97370f0309554f Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Fri, 4 Mar 2011 17:31:52 +0000 Subject: [PATCH] Add unit test showing that bug #50867 works fine git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1078065 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xssf/usermodel/TestXSSFBugs.java | 57 ++++++++++++++++++ test-data/spreadsheet/50867_with_table.xlsx | Bin 0 -> 9458 bytes 2 files changed, 57 insertions(+) create mode 100644 test-data/spreadsheet/50867_with_table.xlsx diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java index eaa8705b09..eaeb01faab 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java @@ -42,6 +42,7 @@ import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.model.CalculationChain; +import org.apache.poi.xssf.model.Table; import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet; @@ -821,4 +822,60 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { cell = row.getCell(2); assertEquals(text, cell.getStringCellValue()); } + + /** + * Adding sheets when one has a table, then re-ordering + */ + public void test50867() throws Exception { + XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("50867_with_table.xlsx"); + assertEquals(3, wb.getNumberOfSheets()); + + XSSFSheet s1 = wb.getSheetAt(0); + XSSFSheet s2 = wb.getSheetAt(1); + XSSFSheet s3 = wb.getSheetAt(2); + assertEquals(1, s1.getTables().size()); + assertEquals(0, s2.getTables().size()); + assertEquals(0, s3.getTables().size()); + + Table t = s1.getTables().get(0); + assertEquals("Tabella1", t.getName()); + assertEquals("Tabella1", t.getDisplayName()); + assertEquals("A1:C3", t.getCTTable().getRef()); + + // Add a sheet and re-order + XSSFSheet s4 = wb.createSheet("NewSheet"); + wb.setSheetOrder(s4.getSheetName(), 0); + + // Check on tables + assertEquals(1, s1.getTables().size()); + assertEquals(0, s2.getTables().size()); + assertEquals(0, s3.getTables().size()); + assertEquals(0, s4.getTables().size()); + + // Refetch to get the new order + s1 = wb.getSheetAt(0); + s2 = wb.getSheetAt(1); + s3 = wb.getSheetAt(2); + s4 = wb.getSheetAt(3); + assertEquals(0, s1.getTables().size()); + assertEquals(1, s2.getTables().size()); + assertEquals(0, s3.getTables().size()); + assertEquals(0, s4.getTables().size()); + + // Save and re-load + wb = XSSFTestDataSamples.writeOutAndReadBack(wb); + s1 = wb.getSheetAt(0); + s2 = wb.getSheetAt(1); + s3 = wb.getSheetAt(2); + s4 = wb.getSheetAt(3); + assertEquals(0, s1.getTables().size()); + assertEquals(1, s2.getTables().size()); + assertEquals(0, s3.getTables().size()); + assertEquals(0, s4.getTables().size()); + + t = s2.getTables().get(0); + assertEquals("Tabella1", t.getName()); + assertEquals("Tabella1", t.getDisplayName()); + assertEquals("A1:C3", t.getCTTable().getRef()); + } } diff --git a/test-data/spreadsheet/50867_with_table.xlsx b/test-data/spreadsheet/50867_with_table.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..b42d6e4964e6b01fe1a1e0db87b257adb757db73 GIT binary patch literal 9458 zcmeHNbyQUC)*oU>=?-b>?hX;8OByAH4jDQmq`Nz%M_L*LX%G;k8w8P%Mv%^LD&N^#m|K>US`R%=b&wh@IJRCeO00Dpm001ZfvG=uj5@7&<1Oxy8 z2QUMpCkeK7GPQLwPi->ts#=vql`z=0m`{hu+CgNpGy6v>D<#FP>ZiIL?X^1XzC2)vQ2-KH=`ybl*0 zCSlrzPxY=M^S`b+#{0U=6q~FQdI1VJ5VNa7yx0c_A>v){ReDtqIw1Zdn2PGz<{F&- z^SE)-Fx%z+DI!kTs{Y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