Fix whitespace

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1563660 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2014-02-02 16:44:30 +00:00
parent e023d34c9a
commit d07ce077f5
2 changed files with 185 additions and 185 deletions

View File

@ -94,191 +94,191 @@ public class EventBasedExcelExtractor extends POIOLE2TextExtractor implements or
return _dir.getFileSystem(); return _dir.getFileSystem();
} }
/** /**
* Would return the document information metadata for the document, * Would return the document information metadata for the document,
* if we supported it * if we supported it
*/ */
public DocumentSummaryInformation getDocSummaryInformation() { public DocumentSummaryInformation getDocSummaryInformation() {
throw new IllegalStateException("Metadata extraction not supported in streaming mode, please use ExcelExtractor"); throw new IllegalStateException("Metadata extraction not supported in streaming mode, please use ExcelExtractor");
} }
/** /**
* Would return the summary information metadata for the document, * Would return the summary information metadata for the document,
* if we supported it * if we supported it
*/ */
public SummaryInformation getSummaryInformation() { public SummaryInformation getSummaryInformation() {
throw new IllegalStateException("Metadata extraction not supported in streaming mode, please use ExcelExtractor"); throw new IllegalStateException("Metadata extraction not supported in streaming mode, please use ExcelExtractor");
} }
/** /**
* Would control the inclusion of cell comments from the document, * Would control the inclusion of cell comments from the document,
* if we supported it * if we supported it
*/ */
public void setIncludeCellComments(boolean includeComments) { public void setIncludeCellComments(boolean includeComments) {
throw new IllegalStateException("Comment extraction not supported in streaming mode, please use ExcelExtractor"); throw new IllegalStateException("Comment extraction not supported in streaming mode, please use ExcelExtractor");
} }
/** /**
* Would control the inclusion of headers and footers from the document, * Would control the inclusion of headers and footers from the document,
* if we supported it * if we supported it
*/ */
public void setIncludeHeadersFooters(boolean includeHeadersFooters) { public void setIncludeHeadersFooters(boolean includeHeadersFooters) {
throw new IllegalStateException("Header/Footer extraction not supported in streaming mode, please use ExcelExtractor"); throw new IllegalStateException("Header/Footer extraction not supported in streaming mode, please use ExcelExtractor");
} }
/** /**
* Should sheet names be included? Default is true * Should sheet names be included? Default is true
*/ */
public void setIncludeSheetNames(boolean includeSheetNames) { public void setIncludeSheetNames(boolean includeSheetNames) {
_includeSheetNames = includeSheetNames; _includeSheetNames = includeSheetNames;
} }
/** /**
* Should we return the formula itself, and not * Should we return the formula itself, and not
* the result it produces? Default is false * the result it produces? Default is false
*/ */
public void setFormulasNotResults(boolean formulasNotResults) { public void setFormulasNotResults(boolean formulasNotResults) {
_formulasNotResults = formulasNotResults; _formulasNotResults = formulasNotResults;
} }
/** /**
* Retreives the text contents of the file * Retreives the text contents of the file
*/ */
public String getText() { public String getText() {
String text = null; String text = null;
try { try {
TextListener tl = triggerExtraction(); TextListener tl = triggerExtraction();
text = tl._text.toString(); text = tl._text.toString();
if(! text.endsWith("\n")) { if(! text.endsWith("\n")) {
text = text + "\n"; text = text + "\n";
} }
} catch(IOException e) { } catch(IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
return text; return text;
} }
private TextListener triggerExtraction() throws IOException { private TextListener triggerExtraction() throws IOException {
TextListener tl = new TextListener(); TextListener tl = new TextListener();
FormatTrackingHSSFListener ft = new FormatTrackingHSSFListener(tl); FormatTrackingHSSFListener ft = new FormatTrackingHSSFListener(tl);
tl._ft = ft; tl._ft = ft;
// Register and process // Register and process
HSSFEventFactory factory = new HSSFEventFactory(); HSSFEventFactory factory = new HSSFEventFactory();
HSSFRequest request = new HSSFRequest(); HSSFRequest request = new HSSFRequest();
request.addListenerForAllRecords(ft); request.addListenerForAllRecords(ft);
factory.processWorkbookEvents(request, _dir); factory.processWorkbookEvents(request, _dir);
return tl; return tl;
} }
private class TextListener implements HSSFListener { private class TextListener implements HSSFListener {
FormatTrackingHSSFListener _ft; FormatTrackingHSSFListener _ft;
private SSTRecord sstRecord; private SSTRecord sstRecord;
private final List<String> sheetNames; private final List<String> sheetNames;
final StringBuffer _text = new StringBuffer(); final StringBuffer _text = new StringBuffer();
private int sheetNum = -1; private int sheetNum = -1;
private int rowNum; private int rowNum;
private boolean outputNextStringValue = false; private boolean outputNextStringValue = false;
private int nextRow = -1; private int nextRow = -1;
public TextListener() { public TextListener() {
sheetNames = new ArrayList<String>(); sheetNames = new ArrayList<String>();
} }
public void processRecord(Record record) { public void processRecord(Record record) {
String thisText = null; String thisText = null;
int thisRow = -1; int thisRow = -1;
switch(record.getSid()) { switch(record.getSid()) {
case BoundSheetRecord.sid: case BoundSheetRecord.sid:
BoundSheetRecord sr = (BoundSheetRecord)record; BoundSheetRecord sr = (BoundSheetRecord)record;
sheetNames.add(sr.getSheetname()); sheetNames.add(sr.getSheetname());
break; break;
case BOFRecord.sid: case BOFRecord.sid:
BOFRecord bof = (BOFRecord)record; BOFRecord bof = (BOFRecord)record;
if(bof.getType() == BOFRecord.TYPE_WORKSHEET) { if(bof.getType() == BOFRecord.TYPE_WORKSHEET) {
sheetNum++; sheetNum++;
rowNum = -1; rowNum = -1;
if(_includeSheetNames) { if(_includeSheetNames) {
if(_text.length() > 0) _text.append("\n"); if(_text.length() > 0) _text.append("\n");
_text.append(sheetNames.get(sheetNum)); _text.append(sheetNames.get(sheetNum));
} }
} }
break; break;
case SSTRecord.sid: case SSTRecord.sid:
sstRecord = (SSTRecord)record; sstRecord = (SSTRecord)record;
break; break;
case FormulaRecord.sid: case FormulaRecord.sid:
FormulaRecord frec = (FormulaRecord) record; FormulaRecord frec = (FormulaRecord) record;
thisRow = frec.getRow(); thisRow = frec.getRow();
if(_formulasNotResults) { if(_formulasNotResults) {
thisText = HSSFFormulaParser.toFormulaString((HSSFWorkbook)null, frec.getParsedExpression()); thisText = HSSFFormulaParser.toFormulaString((HSSFWorkbook)null, frec.getParsedExpression());
} else { } else {
if(frec.hasCachedResultString()) { if(frec.hasCachedResultString()) {
// Formula result is a string // Formula result is a string
// This is stored in the next record // This is stored in the next record
outputNextStringValue = true; outputNextStringValue = true;
nextRow = frec.getRow(); nextRow = frec.getRow();
} else { } else {
thisText = _ft.formatNumberDateCell(frec); thisText = _ft.formatNumberDateCell(frec);
} }
} }
break; break;
case StringRecord.sid: case StringRecord.sid:
if(outputNextStringValue) { if(outputNextStringValue) {
// String for formula // String for formula
StringRecord srec = (StringRecord)record; StringRecord srec = (StringRecord)record;
thisText = srec.getString(); thisText = srec.getString();
thisRow = nextRow; thisRow = nextRow;
outputNextStringValue = false; outputNextStringValue = false;
} }
break; break;
case LabelRecord.sid: case LabelRecord.sid:
LabelRecord lrec = (LabelRecord) record; LabelRecord lrec = (LabelRecord) record;
thisRow = lrec.getRow(); thisRow = lrec.getRow();
thisText = lrec.getValue(); thisText = lrec.getValue();
break; break;
case LabelSSTRecord.sid: case LabelSSTRecord.sid:
LabelSSTRecord lsrec = (LabelSSTRecord) record; LabelSSTRecord lsrec = (LabelSSTRecord) record;
thisRow = lsrec.getRow(); thisRow = lsrec.getRow();
if(sstRecord == null) { if(sstRecord == null) {
throw new IllegalStateException("No SST record found"); throw new IllegalStateException("No SST record found");
} }
thisText = sstRecord.getString(lsrec.getSSTIndex()).toString(); thisText = sstRecord.getString(lsrec.getSSTIndex()).toString();
break; break;
case NoteRecord.sid: case NoteRecord.sid:
NoteRecord nrec = (NoteRecord) record; NoteRecord nrec = (NoteRecord) record;
thisRow = nrec.getRow(); thisRow = nrec.getRow();
// TODO: Find object to match nrec.getShapeId() // TODO: Find object to match nrec.getShapeId()
break; break;
case NumberRecord.sid: case NumberRecord.sid:
NumberRecord numrec = (NumberRecord) record; NumberRecord numrec = (NumberRecord) record;
thisRow = numrec.getRow(); thisRow = numrec.getRow();
thisText = _ft.formatNumberDateCell(numrec); thisText = _ft.formatNumberDateCell(numrec);
break; break;
default: default:
break; break;
} }
if(thisText != null) { if(thisText != null) {
if(thisRow != rowNum) { if(thisRow != rowNum) {
rowNum = thisRow; rowNum = thisRow;
if(_text.length() > 0) if(_text.length() > 0)
_text.append("\n"); _text.append("\n");
} else { } else {
_text.append("\t"); _text.append("\t");
} }
_text.append(thisText); _text.append(thisText);
} }
} }
} }
} }

View File

@ -21,16 +21,16 @@ package org.apache.poi.ss.extractor;
* HSSF and XSSF * HSSF and XSSF
*/ */
public interface ExcelExtractor { public interface ExcelExtractor {
/** /**
* Should sheet names be included? Default is true * Should sheet names be included? Default is true
*/ */
public void setIncludeSheetNames(boolean includeSheetNames); public void setIncludeSheetNames(boolean includeSheetNames);
/** /**
* Should we return the formula itself, and not * Should we return the formula itself, and not
* the result it produces? Default is false * the result it produces? Default is false
*/ */
public void setFormulasNotResults(boolean formulasNotResults); public void setFormulasNotResults(boolean formulasNotResults);
/** /**
* Should headers and footers be included in the output? * Should headers and footers be included in the output?
@ -38,13 +38,13 @@ public interface ExcelExtractor {
*/ */
public void setIncludeHeadersFooters(boolean includeHeadersFooters); public void setIncludeHeadersFooters(boolean includeHeadersFooters);
/** /**
* Should cell comments be included? Default is false * Should cell comments be included? Default is false
*/ */
public void setIncludeCellComments(boolean includeCellComments); public void setIncludeCellComments(boolean includeCellComments);
/** /**
* Retreives the text contents of the file * Retreives the text contents of the file
*/ */
public String getText(); public String getText();
} }