]> source.dussan.org Git - poi.git/commitdiff
Bug 57231: Add missing ArrayRecord.clone()
authorDominik Stadler <centic@apache.org>
Mon, 22 Dec 2014 08:17:56 +0000 (08:17 +0000)
committerDominik Stadler <centic@apache.org>
Mon, 22 Dec 2014 08:17:56 +0000 (08:17 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1647255 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/record/ArrayRecord.java
src/testcases/org/apache/poi/hssf/record/TestArrayRecord.java
test-data/spreadsheet/57231_MixedGasReport.xls [new file with mode: 0644]

index de32a633475bbce09d02173977ec3cded0819ce2..919822858a72eae7a34c6df88b319877c824036a 100644 (file)
@@ -94,5 +94,15 @@ public final class ArrayRecord extends SharedValueRecordBase {
                }
                sb.append("]");
                return sb.toString();
-       }
+       }       
+    
+    public Object clone() {
+        ArrayRecord rec = new ArrayRecord(_formula.copy(), getRange());
+
+        // they both seem unused, but clone them nevertheless to have an exact copy
+        rec._options = _options;
+        rec._field3notUsed = _field3notUsed;
+
+        return rec;
+    }
 }
index d2b483f407f8b49ffe1ace80cad6dddcecc7d861..ff5fe0ad9b8c27daf229b1f919f4b0c923b6c700 100644 (file)
@@ -19,14 +19,17 @@ package org.apache.poi.hssf.record;
 
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.util.CellRangeAddress8Bit;
-import org.apache.poi.ss.formula.ptg.Ptg;
+import org.apache.poi.ss.formula.Formula;
 import org.apache.poi.ss.formula.FormulaParser;
 import org.apache.poi.ss.formula.FormulaRenderer;
 import org.apache.poi.ss.formula.FormulaType;
-import org.apache.poi.ss.formula.Formula;
-import org.apache.poi.util.HexRead;
+import org.apache.poi.ss.formula.ptg.Ptg;
 import org.apache.poi.util.HexDump;
+import org.apache.poi.util.HexRead;
 
 public final class TestArrayRecord extends TestCase {
 
@@ -53,7 +56,22 @@ public final class TestArrayRecord extends TestCase {
         byte[] ser = r2.serialize();
         //serialize and check that the data is the same as in r1
         assertEquals(HexDump.toHex(data), HexDump.toHex(ser));
+    }
+
+    public void testBug57231() {
+        HSSFWorkbook wb = HSSFTestDataSamples
+                .openSampleWorkbook("57231_MixedGasReport.xls");
+        HSSFSheet sheet = wb.getSheet("master");
+
+        HSSFSheet newSheet = wb.cloneSheet(wb.getSheetIndex(sheet));
+        int idx = wb.getSheetIndex(newSheet);
+        wb.setSheetName(idx, "newName");
 
+        // Write the output to a file
+        HSSFWorkbook wbBack = HSSFTestDataSamples.writeOutAndReadBack(wb);
+        assertNotNull(wbBack);
 
+        assertNotNull(wbBack.getSheet("master"));
+        assertNotNull(wbBack.getSheet("newName"));
     }
-}
\ No newline at end of file
+}
diff --git a/test-data/spreadsheet/57231_MixedGasReport.xls b/test-data/spreadsheet/57231_MixedGasReport.xls
new file mode 100644 (file)
index 0000000..d4a526c
Binary files /dev/null and b/test-data/spreadsheet/57231_MixedGasReport.xls differ