Add clone methods to DrawingRecord and AbstractEscherHolderRecord, which allows cloning of some sheets with drawing objects on them. Fixes bug #31795
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@610336 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
50e62c9bcf
commit
f9e5145d9c
@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
<!-- Don't forget to update status.xml too! -->
|
<!-- Don't forget to update status.xml too! -->
|
||||||
<release version="3.0.2-FINAL" date="2008-??-??">
|
<release version="3.0.2-FINAL" date="2008-??-??">
|
||||||
|
<action dev="POI-DEVELOPERS" type="fix">31795 - Support cloning of sheets with certain drawing objects on them</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">43902 - Don't consider merged regions when auto-sizing columns</action>
|
<action dev="POI-DEVELOPERS" type="fix">43902 - Don't consider merged regions when auto-sizing columns</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">42464 - Avoid "Expected ExpPtg to be converted from Shared to Non-Shared Formula" on large, formula heavy worksheets</action>
|
<action dev="POI-DEVELOPERS" type="fix">42464 - Avoid "Expected ExpPtg to be converted from Shared to Non-Shared Formula" on large, formula heavy worksheets</action>
|
||||||
<action dev="POI-DEVELOPERS" type="add">42033 - Add support for named ranges with unicode names</action>
|
<action dev="POI-DEVELOPERS" type="add">42033 - Add support for named ranges with unicode names</action>
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
<!-- Don't forget to update changes.xml too! -->
|
<!-- Don't forget to update changes.xml too! -->
|
||||||
<changes>
|
<changes>
|
||||||
<release version="3.0.2-FINAL" date="2008-??-??">
|
<release version="3.0.2-FINAL" date="2008-??-??">
|
||||||
|
<action dev="POI-DEVELOPERS" type="fix">31795 - Support cloning of sheets with certain drawing objects on them</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">43902 - Don't consider merged regions when auto-sizing columns</action>
|
<action dev="POI-DEVELOPERS" type="fix">43902 - Don't consider merged regions when auto-sizing columns</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">42464 - Avoid "Expected ExpPtg to be converted from Shared to Non-Shared Formula" on large, formula heavy worksheets</action>
|
<action dev="POI-DEVELOPERS" type="fix">42464 - Avoid "Expected ExpPtg to be converted from Shared to Non-Shared Formula" on large, formula heavy worksheets</action>
|
||||||
<action dev="POI-DEVELOPERS" type="add">42033 - Add support for named ranges with unicode names</action>
|
<action dev="POI-DEVELOPERS" type="add">42033 - Add support for named ranges with unicode names</action>
|
||||||
|
@ -24,6 +24,9 @@ import org.apache.poi.ddf.EscherRecordFactory;
|
|||||||
import org.apache.poi.ddf.NullEscherSerializationListener;
|
import org.apache.poi.ddf.NullEscherSerializationListener;
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.util.LittleEndian;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -76,7 +79,7 @@ public abstract class AbstractEscherHolderRecord
|
|||||||
{
|
{
|
||||||
if (id != getSid())
|
if (id != getSid())
|
||||||
{
|
{
|
||||||
throw new RecordFormatException("Not an escher record");
|
throw new RecordFormatException("Not an escher record! (sid was " + id + ", expecting " + getSid() + ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,7 +230,19 @@ public abstract class AbstractEscherHolderRecord
|
|||||||
|
|
||||||
public Object clone()
|
public Object clone()
|
||||||
{
|
{
|
||||||
throw new IllegalStateException("Not implemented yet.");
|
// Do it via a re-serialise
|
||||||
|
// It's a cheat, but it works...
|
||||||
|
byte[] b = serialize();
|
||||||
|
RecordInputStream rinp = new RecordInputStream(
|
||||||
|
new ByteArrayInputStream(b)
|
||||||
|
);
|
||||||
|
rinp.nextRecord();
|
||||||
|
|
||||||
|
Record[] r = RecordFactory.createRecord(rinp);
|
||||||
|
if(r.length != 1) {
|
||||||
|
throw new IllegalStateException("Re-serialised a record to clone it, but got " + r.length + " records back!");
|
||||||
|
}
|
||||||
|
return r[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addEscherRecord(int index, EscherRecord element)
|
public void addEscherRecord(int index, EscherRecord element)
|
||||||
|
@ -107,15 +107,16 @@ public class DrawingRecord extends Record
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
if (recordData == null) {
|
|
||||||
recordData = new byte[ 0 ];
|
|
||||||
}
|
|
||||||
|
|
||||||
DrawingRecord rec = new DrawingRecord();
|
DrawingRecord rec = new DrawingRecord();
|
||||||
|
|
||||||
|
if (recordData != null) {
|
||||||
rec.recordData = new byte[ recordData.length ];
|
rec.recordData = new byte[ recordData.length ];
|
||||||
rec.contd = new byte[ contd.length ];
|
|
||||||
System.arraycopy(recordData, 0, rec.recordData, 0, recordData.length);
|
System.arraycopy(recordData, 0, rec.recordData, 0, recordData.length);
|
||||||
|
}
|
||||||
|
if (contd != null) {
|
||||||
System.arraycopy(contd, 0, rec.contd, 0, contd.length);
|
System.arraycopy(contd, 0, rec.contd, 0, contd.length);
|
||||||
|
rec.contd = new byte[ contd.length ];
|
||||||
|
}
|
||||||
|
|
||||||
return rec;
|
return rec;
|
||||||
}
|
}
|
||||||
|
BIN
src/testcases/org/apache/poi/hssf/data/SheetWithDrawing.xls
Normal file
BIN
src/testcases/org/apache/poi/hssf/data/SheetWithDrawing.xls
Normal file
Binary file not shown.
@ -109,4 +109,24 @@ public class TestHSSFWorkbook extends TestCase
|
|||||||
assertEquals(b.getSelectedTab(), 1);
|
assertEquals(b.getSelectedTab(), 1);
|
||||||
assertEquals(b.getDisplayedTab(), 1);
|
assertEquals(b.getDisplayedTab(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSheetClone() throws Exception {
|
||||||
|
// First up, try a simple file
|
||||||
|
HSSFWorkbook b = new HSSFWorkbook();
|
||||||
|
assertEquals(0, b.getNumberOfSheets());
|
||||||
|
b.createSheet("Sheet One");
|
||||||
|
b.createSheet("Sheet Two");
|
||||||
|
|
||||||
|
assertEquals(2, b.getNumberOfSheets());
|
||||||
|
b.cloneSheet(0);
|
||||||
|
assertEquals(3, b.getNumberOfSheets());
|
||||||
|
|
||||||
|
// Now try a problem one with drawing records in it
|
||||||
|
b = new HSSFWorkbook(
|
||||||
|
new FileInputStream(new File(filename,"SheetWithDrawing.xls"))
|
||||||
|
);
|
||||||
|
assertEquals(1, b.getNumberOfSheets());
|
||||||
|
b.cloneSheet(0);
|
||||||
|
assertEquals(2, b.getNumberOfSheets());
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user