aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2013-11-02 10:01:01 +0000
committerDominik Stadler <centic@apache.org>2013-11-02 10:01:01 +0000
commit9d7c124057212989de04fce634d7343e4e7b2c0b (patch)
treea3e2d2cd81981549138ac47835a602c18fda33e5 /src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
parent2881930651f926afb12ab4aed62b6e7e59dc860d (diff)
downloadpoi-9d7c124057212989de04fce634d7343e4e7b2c0b.tar.gz
poi-9d7c124057212989de04fce634d7343e4e7b2c0b.zip
Fix Bug 54400 by updating the index in the LinkTable whenever sheets are
removed. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1538163 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java')
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
index 1927727e42..88fa84ac21 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
@@ -48,6 +48,7 @@ import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.formula.ptg.Area3DPtg;
import org.apache.poi.ss.usermodel.BaseTestWorkbook;
+import org.apache.poi.ss.usermodel.Name;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.TempFile;
@@ -965,4 +966,53 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
HSSFWorkbook read = HSSFTestDataSamples.writeOutAndReadBack(wb);
assertSheetOrder(read, "Invoice", "Deferred", "Received", "Digest");
}
+
+ public void testBug54500() throws Exception {
+ String nameName = "AName";
+ String sheetName = "ASheet";
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("54500.xls");
+
+ assertSheetOrder(wb, "Sheet1", "Sheet2", "Sheet3");
+
+ wb.createSheet(sheetName);
+
+ assertSheetOrder(wb, "Sheet1", "Sheet2", "Sheet3", "ASheet");
+
+ Name n = wb.createName();
+ n.setNameName(nameName);
+ n.setSheetIndex(3);
+ n.setRefersToFormula(sheetName + "!A1");
+
+ assertSheetOrder(wb, "Sheet1", "Sheet2", "Sheet3", "ASheet");
+ assertEquals("ASheet!A1", wb.getName(nameName).getRefersToFormula());
+
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ wb.write(stream);
+
+ assertSheetOrder(wb, "Sheet1", "Sheet2", "Sheet3", "ASheet");
+ assertEquals("ASheet!A1", wb.getName(nameName).getRefersToFormula());
+
+ wb.removeSheetAt(1);
+
+ assertSheetOrder(wb, "Sheet1", "Sheet3", "ASheet");
+ assertEquals("ASheet!A1", wb.getName(nameName).getRefersToFormula());
+
+ ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
+ wb.write(stream2);
+
+ assertSheetOrder(wb, "Sheet1", "Sheet3", "ASheet");
+ assertEquals("ASheet!A1", wb.getName(nameName).getRefersToFormula());
+
+ expectName(
+ new HSSFWorkbook(new ByteArrayInputStream(stream.toByteArray())),
+ nameName, "ASheet!A1");
+ expectName(
+ new HSSFWorkbook(
+ new ByteArrayInputStream(stream2.toByteArray())),
+ nameName, "ASheet!A1");
+ }
+
+ private void expectName(HSSFWorkbook wb, String name, String expect) {
+ assertEquals(expect, wb.getName(name).getRefersToFormula());
+ }
}