int aggLoc = sheet.aggregateDrawingRecords(drawingManager, false);
if(aggLoc != -1) {
EscherAggregate agg = (EscherAggregate) sheet.findFirstRecordBySid(EscherAggregate.sid);
+ EscherContainerRecord escherContainer = agg.getEscherContainer();
+ if (escherContainer == null) {
+ return;
+ }
EscherDggRecord dgg = drawingManager.getDgg();
dgg.setDrawingsSaved(dgg.getDrawingsSaved() + 1);
EscherDgRecord dg = null;
- for(Iterator it = agg.getEscherContainer().getChildRecords().iterator(); it.hasNext();) {
+ for(Iterator it = escherContainer.getChildRecords().iterator(); it.hasNext();) {
Object er = it.next();
if(er instanceof EscherDgRecord) {
dg = (EscherDgRecord)er;
private short field_1_option_flag;
private byte field_2_keyboard_shortcut;
- private short field_5_index_to_sheet; // unused: see field_6
- /** the one based sheet number. Zero if this is a global name */
+ /** One-based extern index of sheet (resolved via LinkTable). Zero if this is a global name */
+ private short field_5_externSheetIndex_plus1;
+ /** the one based sheet number. */
private int field_6_sheetNumber;
private boolean field_11_nameIsMultibyte;
private byte field_12_built_in_code;
/**
* For named ranges, and built-in names
- * @return the 1-based sheet number. Zero if this is a global name
+ * @return the 1-based sheet number.
*/
public int getSheetNumber()
{
LittleEndian.putByte(data, 7 + offset, getNameTextLength());
// Note -
LittleEndian.putUShort(data, 8 + offset, Ptg.getEncodedSizeWithoutArrayData(field_13_name_definition));
- LittleEndian.putUShort(data, 10 + offset, field_5_index_to_sheet);
+ LittleEndian.putUShort(data, 10 + offset, field_5_externSheetIndex_plus1);
LittleEndian.putUShort(data, 12 + offset, field_6_sheetNumber);
LittleEndian.putByte(data, 14 + offset, field_7_length_custom_menu);
LittleEndian.putByte(data, 15 + offset, field_8_length_description_text);
field_2_keyboard_shortcut = in.readByte();
int field_3_length_name_text = in.readByte();
int field_4_length_name_definition = in.readShort();
- field_5_index_to_sheet = in.readShort();
+ field_5_externSheetIndex_plus1 = in.readShort();
field_6_sheetNumber = in.readUShort();
int field_7_length_custom_menu = in.readUByte();
int field_8_length_description_text = in.readUByte();
sb.append(" .option flags = ").append(HexDump.shortToHex(field_1_option_flag)).append("\n");
sb.append(" .keyboard shortcut = ").append(HexDump.byteToHex(field_2_keyboard_shortcut)).append("\n");
sb.append(" .length of the name = ").append(getNameTextLength()).append("\n");
- sb.append(" .unused = ").append( field_5_index_to_sheet ).append("\n");
- sb.append(" .index to sheet (1-based, 0=Global) = ").append( field_6_sheetNumber ).append("\n");
+ sb.append(" .extSheetIx(1-based, 0=Global)= ").append( field_5_externSheetIndex_plus1 ).append("\n");
+ sb.append(" .sheetTabIx = ").append(field_6_sheetNumber ).append("\n");
sb.append(" .Menu text length = ").append(field_14_custom_menu_text.length()).append("\n");
sb.append(" .Description text length= ").append(field_15_description_text.length()).append("\n");
sb.append(" .Help topic text length = ").append(field_16_help_topic_text.length()).append("\n");
}
}
}
+
+ /**
+ * Test to make sure that NameRecord.getSheetNumber() is interpreted as a
+ * 1-based sheet tab index (not a 1-based extern sheet index)
+ */
+ public void testFindBuiltInNameRecord() {
+ // testRRaC has multiple (3) built-in name records
+ // The second print titles name record has getSheetNumber()==4
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("testRRaC.xls");
+ NameRecord nr;
+ assertEquals(3, wb.getWorkbook().getNumNames());
+ nr = wb.getWorkbook().getNameRecord(2);
+ // TODO - render full row and full column refs properly
+ assertEquals("Sheet2!$A$1:$IV$1", nr.getAreaReference(wb)); // 1:1
+
+ try {
+ wb.setRepeatingRowsAndColumns(3, 4, 5, 8, 11);
+ } catch (RuntimeException e) {
+ if (e.getMessage().equals("Builtin (7) already exists for sheet (4)")) {
+ // there was a problem in the code which locates the existing print titles name record
+ throw new RuntimeException("Identified bug 45720b");
+ }
+ throw e;
+ }
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
+ assertEquals(3, wb.getWorkbook().getNumNames());
+ nr = wb.getWorkbook().getNameRecord(2);
+ assertEquals("Sheet2!E:F,Sheet2!$A$9:$IV$12", nr.getAreaReference(wb)); // E:F,9:12
+ }
}