use of org.apache.poi.hssf.record.OldFormulaRecord in project poi by apache.
the class OldExcelExtractor method getText.
/**
* Retrieves the text contents of the file, as best we can
* for these old file formats
*
* @return the text contents of the file
*/
public String getText() {
StringBuffer text = new StringBuffer();
// To track formats and encodings
CodepageRecord codepage = null;
// Process each record in turn, looking for interesting ones
while (ris.hasNextRecord()) {
int sid = ris.getNextSid();
ris.nextRecord();
switch(sid) {
case FILE_PASS_RECORD_SID:
throw new EncryptedDocumentException("Encryption not supported for Old Excel files");
case OldSheetRecord.sid:
OldSheetRecord shr = new OldSheetRecord(ris);
shr.setCodePage(codepage);
text.append("Sheet: ");
text.append(shr.getSheetname());
text.append('\n');
break;
case OldLabelRecord.biff2_sid:
case OldLabelRecord.biff345_sid:
OldLabelRecord lr = new OldLabelRecord(ris);
lr.setCodePage(codepage);
text.append(lr.getValue());
text.append('\n');
break;
case OldStringRecord.biff2_sid:
case OldStringRecord.biff345_sid:
OldStringRecord sr = new OldStringRecord(ris);
sr.setCodePage(codepage);
text.append(sr.getString());
text.append('\n');
break;
case NumberRecord.sid:
NumberRecord nr = new NumberRecord(ris);
handleNumericCell(text, nr.getValue());
break;
case OldFormulaRecord.biff2_sid:
case OldFormulaRecord.biff3_sid:
case OldFormulaRecord.biff4_sid:
// Biff 2 and 5+ share the same SID, due to a bug...
if (biffVersion == 5) {
FormulaRecord fr = new FormulaRecord(ris);
if (fr.getCachedResultType() == CellType.NUMERIC.getCode()) {
handleNumericCell(text, fr.getValue());
}
} else {
OldFormulaRecord fr = new OldFormulaRecord(ris);
if (fr.getCachedResultType() == CellType.NUMERIC.getCode()) {
handleNumericCell(text, fr.getValue());
}
}
break;
case RKRecord.sid:
RKRecord rr = new RKRecord(ris);
handleNumericCell(text, rr.getRKNumber());
break;
case CodepageRecord.sid:
codepage = new CodepageRecord(ris);
break;
default:
ris.readFully(new byte[ris.remaining()]);
}
}
close();
ris = null;
return text.toString();
}
Aggregations