Fix for bug 45698 - allow LinkTable to read EXTERNSHEET records
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@689704 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
12e76ef706
commit
7000eed3a9
@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
<!-- Don't forget to update status.xml too! -->
|
<!-- Don't forget to update status.xml too! -->
|
||||||
<release version="3.1.1-alpha1" date="2008-??-??">
|
<release version="3.1.1-alpha1" date="2008-??-??">
|
||||||
|
<action dev="POI-DEVELOPERS" type="fix">45698 - Fix LinkTable to tolerate multiple EXTERNSHEET records</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">45682 - Fix for cloning of CFRecordsAggregate</action>
|
<action dev="POI-DEVELOPERS" type="fix">45682 - Fix for cloning of CFRecordsAggregate</action>
|
||||||
<action dev="POI-DEVELOPERS" type="add">Initial support for evaluating external add-in functions like YEARFRAC</action>
|
<action dev="POI-DEVELOPERS" type="add">Initial support for evaluating external add-in functions like YEARFRAC</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">45672 - Fix for MissingRecordAwareHSSFListener to prevent multiple LastCellOfRowDummyRecords when shared formulas are present</action>
|
<action dev="POI-DEVELOPERS" type="fix">45672 - Fix for MissingRecordAwareHSSFListener to prevent multiple LastCellOfRowDummyRecords when shared formulas are present</action>
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
<!-- Don't forget to update changes.xml too! -->
|
<!-- Don't forget to update changes.xml too! -->
|
||||||
<changes>
|
<changes>
|
||||||
<release version="3.1.1-alpha1" date="2008-??-??">
|
<release version="3.1.1-alpha1" date="2008-??-??">
|
||||||
|
<action dev="POI-DEVELOPERS" type="fix">45698 - Fix LinkTable to tolerate multiple EXTERNSHEET records</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">45682 - Fix for cloning of CFRecordsAggregate</action>
|
<action dev="POI-DEVELOPERS" type="fix">45682 - Fix for cloning of CFRecordsAggregate</action>
|
||||||
<action dev="POI-DEVELOPERS" type="add">Initial support for evaluating external add-in functions like YEARFRAC</action>
|
<action dev="POI-DEVELOPERS" type="add">Initial support for evaluating external add-in functions like YEARFRAC</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">45672 - Fix for MissingRecordAwareHSSFListener to prevent multiple LastCellOfRowDummyRecords when shared formulas are present</action>
|
<action dev="POI-DEVELOPERS" type="fix">45672 - Fix for MissingRecordAwareHSSFListener to prevent multiple LastCellOfRowDummyRecords when shared formulas are present</action>
|
||||||
|
@ -159,8 +159,7 @@ final class LinkTable {
|
|||||||
|
|
||||||
if (_externalBookBlocks.length > 0) {
|
if (_externalBookBlocks.length > 0) {
|
||||||
// If any ExternalBookBlock present, there is always 1 of ExternSheetRecord
|
// If any ExternalBookBlock present, there is always 1 of ExternSheetRecord
|
||||||
Record next = rs.getNext();
|
_externSheetRecord = readExtSheetRecord(rs);
|
||||||
_externSheetRecord = (ExternSheetRecord) next;
|
|
||||||
} else {
|
} else {
|
||||||
_externSheetRecord = null;
|
_externSheetRecord = null;
|
||||||
}
|
}
|
||||||
@ -176,6 +175,28 @@ final class LinkTable {
|
|||||||
_workbookRecordList.getRecords().addAll(inputList.subList(startIndex, startIndex + _recordCount));
|
_workbookRecordList.getRecords().addAll(inputList.subList(startIndex, startIndex + _recordCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ExternSheetRecord readExtSheetRecord(RecordStream rs) {
|
||||||
|
List temp = new ArrayList(2);
|
||||||
|
while(rs.peekNextClass() == ExternSheetRecord.class) {
|
||||||
|
temp.add(rs.getNext());
|
||||||
|
}
|
||||||
|
|
||||||
|
int nItems = temp.size();
|
||||||
|
if (nItems < 1) {
|
||||||
|
throw new RuntimeException("Expected an EXTERNSHEET record but got ("
|
||||||
|
+ rs.peekNextClass().getName() + ")");
|
||||||
|
}
|
||||||
|
if (nItems == 1) {
|
||||||
|
// this is the normal case. There should be just one ExternSheetRecord
|
||||||
|
return (ExternSheetRecord) temp.get(0);
|
||||||
|
}
|
||||||
|
// Some apps generate multiple ExternSheetRecords (see bug 45698).
|
||||||
|
// It seems like the best thing to do might be to combine these into one
|
||||||
|
ExternSheetRecord[] esrs = new ExternSheetRecord[nItems];
|
||||||
|
temp.toArray(esrs);
|
||||||
|
return ExternSheetRecord.combine(esrs);
|
||||||
|
}
|
||||||
|
|
||||||
public LinkTable(short numberOfSheets, WorkbookRecordList workbookRecordList) {
|
public LinkTable(short numberOfSheets, WorkbookRecordList workbookRecordList) {
|
||||||
_workbookRecordList = workbookRecordList;
|
_workbookRecordList = workbookRecordList;
|
||||||
_definedNames = new ArrayList();
|
_definedNames = new ArrayList();
|
||||||
|
@ -260,4 +260,16 @@ public class ExternSheetRecord extends Record {
|
|||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ExternSheetRecord combine(ExternSheetRecord[] esrs) {
|
||||||
|
ExternSheetRecord result = new ExternSheetRecord();
|
||||||
|
for (int i = 0; i < esrs.length; i++) {
|
||||||
|
ExternSheetRecord esr = esrs[i];
|
||||||
|
int nRefs = esr.getNumOfREFRecords();
|
||||||
|
for (int j=0; j<nRefs; j++) {
|
||||||
|
result.addREFRecord(esr.getRef(j));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
BIN
src/testcases/org/apache/poi/hssf/data/ex45698-22488.xls
Normal file
BIN
src/testcases/org/apache/poi/hssf/data/ex45698-22488.xls
Normal file
Binary file not shown.
@ -41,4 +41,19 @@ public final class TestLinkTable extends TestCase {
|
|||||||
|
|
||||||
assertEquals("ipcSummenproduktIntern($C5,N$2,$A$9,N$1)", formula);
|
assertEquals("ipcSummenproduktIntern($C5,N$2,$A$9,N$1)", formula);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testMultipleExternSheetRecords_bug45698() {
|
||||||
|
HSSFWorkbook wb;
|
||||||
|
|
||||||
|
try {
|
||||||
|
wb = HSSFTestDataSamples.openSampleWorkbook("ex45698-22488.xls");
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
if ("Extern sheet is part of LinkTable".equals(e.getMessage())) {
|
||||||
|
throw new AssertionFailedError("Identified bug 45698");
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
// some other sanity checks
|
||||||
|
assertEquals(7, wb.getNumberOfSheets());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user