lastDGRecord.join((AbstractEscherHolderRecord) record);
}
else if (record.getSid() == ContinueRecord.sid &&
- (lastRecord instanceof ObjRecord)) {
+ ((lastRecord instanceof ObjRecord) || (lastRecord instanceof TextObjectRecord))) {
// Drawing records have a very strange continue behaviour.
//There can actually be OBJ records mixed between the continues.
lastDrawingRecord.processContinueRecord( ((ContinueRecord)record).getData() );
//Gracefully handle records that we dont know about,
//that happen to be continued
records.add(record);
- } else throw new RecordFormatException("Unhandled Continue Record");
+ } else
+ throw new RecordFormatException("Unhandled Continue Record");
}
else {
lastRecord = record;
public class TextObjectRecord
extends TextObjectBaseRecord
{
- HSSFRichTextString str = new HSSFRichTextString( "" );
+ HSSFRichTextString str;
public TextObjectRecord()
{
public TextObjectRecord( RecordInputStream in )
{
super( in );
+ if (str == null)
+ str = new HSSFRichTextString("");
}
protected void fillFields(RecordInputStream in)
/** Returns true if the row has cells attached to it */
public boolean rowHasCells(int row) {
+ if (row > records.length)
+ return false;
CellValueRecordInterface[] rowCells=records[row];
if(rowCells==null) return false;
for(int col=0;col<rowCells.length;col++) {
windowTwo.setPaged(sheets.size() == 1);
sheets.add(clonedSheet);
- if (srcName.length()<28) {
- workbook.setSheetName(sheets.size()-1, srcName+"(2)");
- }else {
- workbook.setSheetName(sheets.size()-1,srcName.substring(0,28)+"(2)");
+ int i=1;
+ while (true) {
+ //Try and find the next sheet name that is unique
+ String name = srcName;
+ String index = Integer.toString(i++);
+ if (name.length()+index.length()+2<31)
+ name = name + "("+index+")";
+ else name = name.substring(0, 31-index.length()-2)+"("+index+")";
+
+ //If the sheet name is unique, then set it otherwise move on to the next number.
+ if (workbook.getSheetIndex(name) == -1) {
+ workbook.setSheetName(sheets.size()-1, name);
+ break;
+ }
}
return clonedSheet;
}
cell.setCellValue("Difference Check");
assertEquals(cloned.getRow((short)0).getCell((short)0).getStringCellValue(), "clone_test");
}
+
+ /** tests that the sheet name for multiple clones of the same sheet is unique
+ * BUG 37416
+ */
+ public void testCloneSheetMultipleTimes() {
+ HSSFWorkbook workbook = new HSSFWorkbook();
+ HSSFSheet sheet = workbook.createSheet("Test Clone");
+ HSSFRow row = sheet.createRow((short) 0);
+ HSSFCell cell = row.createCell((short) 0);
+ cell.setCellValue("clone_test");
+ //Clone the sheet multiple times
+ workbook.cloneSheet(0);
+ workbook.cloneSheet(0);
+
+ assertNotNull(workbook.getSheet("Test Clone"));
+ assertNotNull(workbook.getSheet("Test Clone(1)"));
+ assertNotNull(workbook.getSheet("Test Clone(2)"));
+ }
/**
* Test that the ProtectRecord is included when creating or cloning a sheet
try
{
- b.setSheetName( 3, "name1"/*JMH, HSSFWorkbook.ENCODING_UTF_16*/ );
+ b.setSheetName( 3, "name1" );
fail();
}
catch ( IllegalArgumentException pass )
{
}
- b.setSheetName( 3, "name2"/*JMH, HSSFWorkbook.ENCODING_UTF_16*/ );
- b.setSheetName( 3, "name2"/*JMH, HSSFWorkbook.ENCODING_UTF_16*/ );
+ b.setSheetName( 3, "name2" );
+ b.setSheetName( 3, "name2" );
b.setSheetName( 3, "name2" );
HSSFWorkbook c = new HSSFWorkbook( );