use of org.apache.poi.hssf.record.RecordFormatException in project poi by apache.
the class FormulaRecordAggregate method handleMissingSharedFormulaRecord.
/**
* Sometimes the shared formula flag "seems" to be erroneously set (because the corresponding
* {@link SharedFormulaRecord} does not exist). Normally this would leave no way of determining
* the {@link Ptg} tokens for the formula. However as it turns out in these
* cases, Excel encodes the unshared {@link Ptg} tokens in the right place (inside the {@link
* FormulaRecord}). So the the only thing that needs to be done is to ignore the erroneous
* shared formula flag.<br/>
*
* This method may also be used for setting breakpoints to help diagnose issues regarding the
* abnormally-set 'shared formula' flags.
* (see TestValueRecordsAggregate.testSpuriousSharedFormulaFlag()).<p/>
*/
private static void handleMissingSharedFormulaRecord(FormulaRecord formula) {
// make sure 'unshared' formula is actually available
Ptg firstToken = formula.getParsedExpression()[0];
if (firstToken instanceof ExpPtg) {
throw new RecordFormatException("SharedFormulaRecord not found for FormulaRecord with (isSharedFormula=true)");
}
// could log an info message here since this is a fairly unusual occurrence.
// no point leaving the flag erroneously set
formula.setSharedFormula(false);
}
use of org.apache.poi.hssf.record.RecordFormatException in project poi by apache.
the class TestSeriesTextRecord method testReserializeLongTitle.
public void testReserializeLongTitle() {
// Hex dump from bug 45784 attachment 22560 streamOffset=0x0CD1
byte[] data = HexRead.readFromString("00 00, " + "82 " + "01 " + "50 00 6C 00 61 00 73 00 6D 00 61 00 20 00 4C 00 " + "65 00 76 00 65 00 6C 00 73 00 20 00 6F 00 66 00 " + "20 00 4C 00 2D 00 30 00 30 00 30 00 31 00 31 00 " + "31 00 32 00 32 00 32 00 2D 00 33 00 33 00 33 00 " + "58 00 34 00 34 00 34 00 20 00 69 00 6E 00 20 00 " + "53 00 44 00 20 00 72 00 61 00 74 00 0A 00 50 00 " + "4F 00 20 00 33 00 2E 00 30 00 20 00 6D 00 67 00 " + "2F 00 6B 00 67 00 20 00 28 00 35 00 2E 00 30 00 " + "20 00 6D 00 4C 00 2F 00 6B 00 67 00 29 00 20 00 " + "69 00 6E 00 20 00 4D 00 65 00 74 00 68 00 6F 00 " + "63 00 65 00 6C 00 0A 00 49 00 56 00 20 00 30 00 " + "2E 00 35 00 20 00 6D 00 67 00 2F 00 6B 00 67 00 " + "20 00 28 00 31 00 2E 00 30 00 20 00 6D 00 4C 00 " + "2F 00 6B 00 67 00 29 00 20 00 69 00 6E 00 20 00 " + "36 00 30 00 25 00 20 00 50 00 45 00 47 00 20 00 " + "32 00 30 00 30 00 0A 00 46 00 20 00 3D 00 61 00 " + "62 00 63 00");
RecordInputStream in = TestcaseRecordInputStream.create(SeriesTextRecord.sid, data);
SeriesTextRecord str;
try {
str = new SeriesTextRecord(in);
} catch (RecordFormatException e) {
if (e.getCause() instanceof IllegalArgumentException) {
// "Bad requested string length (-126)"
throw new AssertionFailedError("Identified bug 45784a");
}
throw e;
}
if (str.getRecordSize() < 0) {
throw new AssertionFailedError("Identified bug 45784b");
}
byte[] ser;
try {
ser = str.serialize();
} catch (Exception e) {
throw new RuntimeException(e);
}
TestcaseRecordInputStream.confirmRecordEncoding(SeriesTextRecord.sid, data, ser);
}
use of org.apache.poi.hssf.record.RecordFormatException in project poi by apache.
the class TestExtendedPivotTableViewFieldsRecord method testSubNameNotPresent_bug46693.
public void testSubNameNotPresent_bug46693() {
// This data came from attachment 23347 of bug 46693 at offset 0xAA43
byte[] data = HexRead.readFromString(// BIFF header
"00 01 14 00" + "1E 14 00 0A FF FF FF FF 00 00 FF FF 00 00 00 00 00 00 00 00");
RecordInputStream in = TestcaseRecordInputStream.create(data);
ExtendedPivotTableViewFieldsRecord rec;
try {
rec = new ExtendedPivotTableViewFieldsRecord(in);
} catch (RecordFormatException e) {
if (e.getMessage().equals("Expected to find a ContinueRecord in order to read remaining 65535 of 65535 chars")) {
throw new AssertionFailedError("Identified bug 46693a");
}
throw e;
}
assertEquals(data.length, rec.getRecordSize());
}
use of org.apache.poi.hssf.record.RecordFormatException in project poi by apache.
the class TestExtendedPivotTableViewFieldsRecord method testOlderFormat_bug46918.
public void testOlderFormat_bug46918() {
// There are 10 SXVDEX records in the file (not uploaded) that originated bugzilla 46918
// They all had the following hex encoding:
byte[] data = HexRead.readFromString("00 01 0A 00 1E 14 00 0A FF FF FF FF 00 00");
RecordInputStream in = TestcaseRecordInputStream.create(data);
ExtendedPivotTableViewFieldsRecord rec;
try {
rec = new ExtendedPivotTableViewFieldsRecord(in);
} catch (RecordFormatException e) {
if (e.getMessage().equals("Not enough data (0) to read requested (2) bytes")) {
throw new AssertionFailedError("Identified bug 46918");
}
throw e;
}
byte[] expReserData = HexRead.readFromString("1E 14 00 0A FF FF FF FF 00 00" + "FF FF 00 00 00 00 00 00 00 00");
TestcaseRecordInputStream.confirmRecordEncoding(ExtendedPivotTableViewFieldsRecord.sid, expReserData, rec.serialize());
}
use of org.apache.poi.hssf.record.RecordFormatException in project poi by apache.
the class TestFormulaRecordAggregate method testExtraStringRecord_bug46213.
/**
* Sometimes a {@link StringRecord} appears after a {@link FormulaRecord} even though the
* formula has evaluated to a text value. This might be more likely to occur when the formula
* <i>can</i> evaluate to a text value.<br/>
* Bug 46213 attachment 22874 has such an extra {@link StringRecord} at stream offset 0x5765.
* This file seems to open in Excel (2007) with no trouble. When it is re-saved, Excel omits
* the extra record. POI should do the same.
*/
public void testExtraStringRecord_bug46213() {
FormulaRecord fr = new FormulaRecord();
fr.setValue(2.0);
StringRecord sr = new StringRecord();
sr.setString("NA");
SharedValueManager svm = SharedValueManager.createEmpty();
FormulaRecordAggregate fra;
try {
fra = new FormulaRecordAggregate(fr, sr, svm);
} catch (RecordFormatException e) {
if ("String record was supplied but formula record flag is not set".equals(e.getMessage())) {
throw new AssertionFailedError("Identified bug 46213");
}
throw e;
}
RecordCollector rc = new RecordCollector();
fra.visitContainedRecords(rc);
Record[] vraRecs = rc.getRecords();
assertEquals(1, vraRecs.length);
assertEquals(fr, vraRecs[0]);
}
Aggregations