* make the tabid record look like the current situation.
*/
private void fixTabIdRecord() {
- Record rec = records.get(records.getTabpos());
// see bug 55982, quite a number of documents do not have a TabIdRecord and
// thus there is no way to do the fixup here,
return;
}
+ Record rec = records.get(records.getTabpos());
+
TabIdRecord tir = ( TabIdRecord ) rec;
short[] tia = new short[ boundsheets.size() ];
/** holds the position of the last bound sheet */
private int bspos;
/** holds the position of the tabid record */
- private int tabpos;
+ private int tabpos = -1;
/** hold the position of the last font record */
private int fontpos;
/** hold the position of the last extended font record */
--- /dev/null
+package org.apache.poi.hssf.model;
+
+import org.apache.poi.hssf.record.chart.ChartRecord;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+
+import static org.apache.poi.hssf.HSSFTestDataSamples.openSampleWorkbook;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class TestWorkbookRecordList {
+
+ @Test
+ public void tabposIsOnlyUpdatedIfWorkbookHasTabIdRecord() throws IOException {
+ try (HSSFWorkbook wb = openSampleWorkbook("55982.xls")) {
+ WorkbookRecordList records = wb.getInternalWorkbook().getWorkbookRecordList();
+ assertEquals(-1, records.getTabpos());
+
+ // Add an arbitrary record to the front of the list
+ records.add(0, new ChartRecord());
+
+ assertEquals(-1, records.getTabpos());
+ }
+ }
+}