From: Yegor Kozlov Date: Thu, 10 Jan 2008 18:04:38 +0000 (+0000) Subject: fixed bug 44200: Sheet not cloneable when Note added to excel cell X-Git-Tag: REL_3_0_3_BETA1~190 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f13f164e72fe6a3c53302d1f015d098426848829;p=poi.git fixed bug 44200: Sheet not cloneable when Note added to excel cell git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@610855 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index e77b99fee2..2617fbb43b 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -36,6 +36,7 @@ + 44200 - Enable cloning of sheets with notes 43008 - Add a moveCell method to HSSFRow, and deprecate setCellNum(), which didn't update things properly 43058 - Support setting row grouping on files from CR IX, which lack GutsRecords 31795 - Support cloning of sheets with certain drawing objects on them diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 3ccb4ddd1f..9e93592fc4 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -33,6 +33,7 @@ + 44200 - Enable cloning of sheets with notes 43008 - Add a moveCell method to HSSFRow, and deprecate setCellNum(), which didn't update things properly 43058 - Support setting row grouping on files from CR IX, which lack GutsRecords 31795 - Support cloning of sheets with certain drawing objects on them diff --git a/src/java/org/apache/poi/hssf/record/NoteRecord.java b/src/java/org/apache/poi/hssf/record/NoteRecord.java index 63c0b1d7dc..a9e83806f8 100644 --- a/src/java/org/apache/poi/hssf/record/NoteRecord.java +++ b/src/java/org/apache/poi/hssf/record/NoteRecord.java @@ -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; + } + } diff --git a/src/java/org/apache/poi/hssf/record/NoteStructureSubRecord.java b/src/java/org/apache/poi/hssf/record/NoteStructureSubRecord.java index 6ad3f8eb63..c99f29be35 100644 --- a/src/java/org/apache/poi/hssf/record/NoteStructureSubRecord.java +++ b/src/java/org/apache/poi/hssf/record/NoteStructureSubRecord.java @@ -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; + } + } diff --git a/src/java/org/apache/poi/hssf/record/TextObjectRecord.java b/src/java/org/apache/poi/hssf/record/TextObjectRecord.java index 97685c9ca2..c8f6669b0f 100644 --- a/src/java/org/apache/poi/hssf/record/TextObjectRecord.java +++ b/src/java/org/apache/poi/hssf/record/TextObjectRecord.java @@ -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 index 0000000000..691afedb80 Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/44200.xls differ diff --git a/src/testcases/org/apache/poi/hssf/data/TestDataValidation.xls b/src/testcases/org/apache/poi/hssf/data/TestDataValidation.xls index 556ea81927..6b71a77f2d 100644 Binary files a/src/testcases/org/apache/poi/hssf/data/TestDataValidation.xls and b/src/testcases/org/apache/poi/hssf/data/TestDataValidation.xls differ diff --git a/src/testcases/org/apache/poi/hssf/record/TestNoteRecord.java b/src/testcases/org/apache/poi/hssf/record/TestNoteRecord.java index 5d45094924..2f967b66e6 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestNoteRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestNoteRecord.java @@ -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)); + } } diff --git a/src/testcases/org/apache/poi/hssf/record/TestNoteStructureSubRecord.java b/src/testcases/org/apache/poi/hssf/record/TestNoteStructureSubRecord.java index 833aa66128..d6b5a64766 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestNoteStructureSubRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestNoteStructureSubRecord.java @@ -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)); + } } diff --git a/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java b/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java index 63b9db356f..64e087a554 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java @@ -117,4 +117,44 @@ public class TestTextObjectRecord extends TestCase { } } + + /** + * Test cloning + */ + public void testClone() { + String text = "Hello, World"; + HSSFRichTextString str = new HSSFRichTextString(text); + + TextObjectRecord obj = new TextObjectRecord(); + int frLength = ( str.numFormattingRuns() + 1 ) * 8; + obj.setFormattingRunLength( (short) frLength ); + obj.setTextLength( (short) str.length() ); + obj.setReserved1(true); + obj.setReserved2((short)2); + obj.setReserved3((short)3); + obj.setReserved4((short)4); + obj.setReserved5((short)5); + obj.setReserved6((short)6); + obj.setReserved7((short)7); + obj.setStr( str ); + + + TextObjectRecord cloned = (TextObjectRecord)obj.clone(); + assertEquals(obj.getReserved2(), cloned.getReserved2()); + assertEquals(obj.getReserved3(), cloned.getReserved3()); + assertEquals(obj.getReserved4(), cloned.getReserved4()); + assertEquals(obj.getReserved5(), cloned.getReserved5()); + assertEquals(obj.getReserved6(), cloned.getReserved6()); + assertEquals(obj.getReserved7(), cloned.getReserved7()); + assertEquals(obj.getRecordSize(), cloned.getRecordSize()); + assertEquals(obj.getOptions(), cloned.getOptions()); + assertEquals(obj.getHorizontalTextAlignment(), cloned.getHorizontalTextAlignment()); + assertEquals(obj.getFormattingRunLength(), cloned.getFormattingRunLength()); + assertEquals(obj.getStr().getString(), cloned.getStr().getString()); + + //finally check that the serialized data is the same + byte[] src = obj.serialize(); + byte[] cln = cloned.serialize(); + assertTrue(Arrays.equals(src, cln)); + } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index 75ec3fee60..a3154e3063 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -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); + + } + }