]> source.dussan.org Git - poi.git/commitdiff
fixed bug 44200: Sheet not cloneable when Note added to excel cell
authorYegor Kozlov <yegor@apache.org>
Thu, 10 Jan 2008 18:04:38 +0000 (18:04 +0000)
committerYegor Kozlov <yegor@apache.org>
Thu, 10 Jan 2008 18:04:38 +0000 (18:04 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@610855 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/record/NoteRecord.java
src/java/org/apache/poi/hssf/record/NoteStructureSubRecord.java
src/java/org/apache/poi/hssf/record/TextObjectRecord.java
src/testcases/org/apache/poi/hssf/data/44200.xls [new file with mode: 0755]
src/testcases/org/apache/poi/hssf/data/TestDataValidation.xls
src/testcases/org/apache/poi/hssf/record/TestNoteRecord.java
src/testcases/org/apache/poi/hssf/record/TestNoteStructureSubRecord.java
src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java
src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java

index e77b99fee229b79e3200db6d538dab3474fdd14a..2617fbb43b3d9057b1ea90e502885ae353c16115 100644 (file)
@@ -36,6 +36,7 @@
 
                <!-- Don't forget to update status.xml too! -->
         <release version="3.0.2-FINAL" date="2008-??-??">
+            <action dev="POI-DEVELOPERS" type="fix">44200 - Enable cloning of sheets with notes </action>
             <action dev="POI-DEVELOPERS" type="add">43008 - Add a moveCell method to HSSFRow, and deprecate setCellNum(), which didn't update things properly</action>
             <action dev="POI-DEVELOPERS" type="fix">43058 - Support setting row grouping on files from CR IX, which lack GutsRecords</action>
             <action dev="POI-DEVELOPERS" type="fix">31795 - Support cloning of sheets with certain drawing objects on them</action>
index 3ccb4ddd1fc648baaa88e3f09f89f1a58594e0d8..9e93592fc42699ead7a40ddee8d52e8a004e60c5 100644 (file)
@@ -33,6 +33,7 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.0.2-FINAL" date="2008-??-??">
+            <action dev="POI-DEVELOPERS" type="fix">44200 - Enable cloning of sheets with notes </action>
             <action dev="POI-DEVELOPERS" type="add">43008 - Add a moveCell method to HSSFRow, and deprecate setCellNum(), which didn't update things properly</action>
             <action dev="POI-DEVELOPERS" type="fix">43058 - Support setting row grouping on files from CR IX, which lack GutsRecords</action>
             <action dev="POI-DEVELOPERS" type="fix">31795 - Support cloning of sheets with certain drawing objects on them</action>
index 63c0b1d7dcec30df41e5c7df1fe7417d653d48d0..a9e83806f85d24ecba2319c8db42f0ad7290ba9d 100644 (file)
@@ -243,4 +243,15 @@ public class NoteRecord extends Record {
     public void setAuthor(String author){
         field_5_author = author;
     }
+
+    public Object clone() {
+        NoteRecord rec = new NoteRecord();
+        rec.field_1_row = field_1_row;
+        rec.field_2_col = field_2_col;
+        rec.field_3_flags = field_3_flags;
+        rec.field_4_shapeid = field_4_shapeid;
+        rec.field_5_author = field_5_author;
+        return rec;
+    }
+
 }
index 6ad3f8eb6374c916f2040984e6e567dacdf21c15..c99f29be354942ab2008b927b589fcd8b15932a3 100644 (file)
@@ -125,6 +125,15 @@ public class NoteStructureSubRecord
     {
         return sid;
     }
+
+    public Object clone() {
+        NoteStructureSubRecord rec = new NoteStructureSubRecord();
+        byte[] recdata = new byte[reserved.length];
+        System.arraycopy(reserved, 0, recdata, 0, recdata.length);
+        rec.reserved = recdata;
+        return rec;
+    }
+
 }
 
 
index 97685c9ca21bc7e133b15a08c7bdd6a0eef8cef8..c8f6669b0f2ec9e1ac4938aaa678a4c0e4c5a23e 100644 (file)
@@ -251,4 +251,21 @@ public class TextObjectRecord
         buffer.append( "[/TXO]\n" );
         return buffer.toString();
     }
+
+    public Object clone() {
+
+        TextObjectRecord rec = new TextObjectRecord();
+        rec.str = str;
+
+        rec.setOptions(getOptions());
+        rec.setTextOrientation(getTextOrientation());
+        rec.setReserved4(getReserved4());
+        rec.setReserved5(getReserved5());
+        rec.setReserved6(getReserved6());
+        rec.setTextLength(getTextLength());
+        rec.setFormattingRunLength(getFormattingRunLength());
+        rec.setReserved7(getReserved7());
+        return rec;
+    }
+
 }
diff --git a/src/testcases/org/apache/poi/hssf/data/44200.xls b/src/testcases/org/apache/poi/hssf/data/44200.xls
new file mode 100755 (executable)
index 0000000..691afed
Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/44200.xls differ
index 556ea8192758d22c8b5427a379673771298ee08d..6b71a77f2d0e03b699cecc29f6bc31f5c413e84e 100644 (file)
Binary files a/src/testcases/org/apache/poi/hssf/data/TestDataValidation.xls and b/src/testcases/org/apache/poi/hssf/data/TestDataValidation.xls differ
index 5d450949248ec795e879af99254059b883568023..2f967b66e65729c23d1670f44160b762993e8124 100644 (file)
@@ -79,4 +79,27 @@ public class TestNoteRecord
         System.arraycopy(ser, 4, recdata, 0, recdata.length);
         assertTrue(Arrays.equals(data, recdata));
     }
+
+    public void testClone()
+    {
+        NoteRecord record = new NoteRecord();
+
+        record.setRow((short)1);
+        record.setColumn((short)2);
+        record.setFlags(NoteRecord.NOTE_VISIBLE);
+        record.setShapeId((short)1026);
+        record.setAuthor("Apache Software Foundation");
+
+        NoteRecord cloned = (NoteRecord)record.clone();
+        assertEquals(record.getRow(), cloned.getRow());
+        assertEquals(record.getColumn(), cloned.getColumn());
+        assertEquals(record.getFlags(), cloned.getFlags());
+        assertEquals(record.getShapeId(), cloned.getShapeId());
+        assertEquals(record.getAuthor(), cloned.getAuthor());
+
+        //finally check that the serialized data is the same
+        byte[] src = record.serialize();
+        byte[] cln = cloned.serialize();
+        assertTrue(Arrays.equals(src, cln));
+    }
 }
index 833aa661283ac8bcc89e99ff0fe4efa55e1977d0..d6b5a64766c3b71461e18a469726616b55a5db2b 100644 (file)
@@ -65,4 +65,16 @@ public class TestNoteStructureSubRecord
         assertEquals(ser.length - 4, data.length);
 
     }
+
+    public void testClone()
+    {
+        NoteStructureSubRecord record = new NoteStructureSubRecord();
+        byte[] src = record.serialize();
+
+        NoteStructureSubRecord cloned = (NoteStructureSubRecord)record.clone();
+        byte[] cln = cloned.serialize();
+
+        assertEquals(record.getRecordSize(), cloned.getRecordSize());
+        assertTrue(Arrays.equals(src, cln));
+    }
 }
index 63b9db356f4d82b5f907702f6938121e3723ae5c..64e087a554137e438dc45ed52854911efdb1c264 100644 (file)
@@ -117,4 +117,44 @@ public class TestTextObjectRecord extends TestCase {
         }\r
 \r
     }\r
+\r
+    /**\r
+     * Test cloning\r
+     */\r
+    public void testClone() {\r
+        String text = "Hello, World";\r
+        HSSFRichTextString str = new HSSFRichTextString(text);\r
+\r
+        TextObjectRecord obj = new TextObjectRecord();\r
+        int frLength = ( str.numFormattingRuns() + 1 ) * 8;\r
+        obj.setFormattingRunLength( (short) frLength );\r
+        obj.setTextLength( (short) str.length() );\r
+        obj.setReserved1(true);\r
+        obj.setReserved2((short)2);\r
+        obj.setReserved3((short)3);\r
+        obj.setReserved4((short)4);\r
+        obj.setReserved5((short)5);\r
+        obj.setReserved6((short)6);\r
+        obj.setReserved7((short)7);\r
+        obj.setStr( str );\r
+\r
+\r
+        TextObjectRecord cloned = (TextObjectRecord)obj.clone();\r
+        assertEquals(obj.getReserved2(), cloned.getReserved2());\r
+        assertEquals(obj.getReserved3(), cloned.getReserved3());\r
+        assertEquals(obj.getReserved4(), cloned.getReserved4());\r
+        assertEquals(obj.getReserved5(), cloned.getReserved5());\r
+        assertEquals(obj.getReserved6(), cloned.getReserved6());\r
+        assertEquals(obj.getReserved7(), cloned.getReserved7());\r
+        assertEquals(obj.getRecordSize(), cloned.getRecordSize());\r
+        assertEquals(obj.getOptions(), cloned.getOptions());\r
+        assertEquals(obj.getHorizontalTextAlignment(), cloned.getHorizontalTextAlignment());\r
+        assertEquals(obj.getFormattingRunLength(), cloned.getFormattingRunLength());\r
+        assertEquals(obj.getStr().getString(), cloned.getStr().getString());\r
+\r
+        //finally check that the serialized data is the same\r
+        byte[] src = obj.serialize();\r
+        byte[] cln = cloned.serialize();\r
+        assertTrue(Arrays.equals(src, cln));\r
+    }\r
 }\r
index 75ec3fee60fd5148f0c7297639504476f64461a5..a3154e306342fb8265fa75a09d67efb0fa0a1a65 100644 (file)
@@ -913,7 +913,27 @@ extends TestCase {
 
     }
 
-    
+    /**
+     * Bug 44200: Sheet not cloneable when Note added to excel cell
+     */
+    public void test44200() throws Exception {
+        FileInputStream in = new FileInputStream(new File(cwd, "44200.xls"));
+        HSSFWorkbook wb = new HSSFWorkbook(in);
+        in.close();
+
+        wb.cloneSheet(0);
+        assertTrue("No Exceptions while cloning sheet", true);
+
+        //serialize and read again
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        wb.write(out);
+        out.close();
+
+        wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
+        assertTrue("No Exceptions while reading file", true);
+
+    }
+
 }