Apply patch to add endSheet() to the XSSFEventBasedExcelExtractor, fixes bug 60737, thanks to user zakim for the patch

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1809371 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2017-09-23 07:41:27 +00:00
parent 5ed15ac7c2
commit 4a6bb031a0
4 changed files with 18 additions and 18 deletions

View File

@ -40,7 +40,6 @@ import org.apache.poi.hssf.record.NumberRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.SSTRecord;
import org.apache.poi.hssf.record.StringRecord;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
@ -128,7 +127,7 @@ public class EventBasedExcelExtractor extends POIOLE2TextExtractor implements or
* Retreives the text contents of the file
*/
public String getText() {
String text = null;
String text;
try {
TextListener tl = triggerExtraction();

View File

@ -394,6 +394,9 @@ public class XSSFSheetXMLHandler extends DefaultHandler {
} else if ("sheetData".equals(localName)) {
// Handle any "missing" cells which had comments attached
checkForEmptyCellComments(EmptyCellCommentsCheckType.END_OF_SHEET_DATA);
// indicate that this sheet is now done
output.endSheet();
}
else if("oddHeader".equals(localName) || "evenHeader".equals(localName) ||
"firstHeader".equals(localName)) {
@ -502,13 +505,19 @@ public class XSSFSheetXMLHandler extends DefaultHandler {
public interface SheetContentsHandler {
/** A row with the (zero based) row number has started */
public void startRow(int rowNum);
/** A row with the (zero based) row number has ended */
public void endRow(int rowNum);
/**
* A cell, with the given formatted value (may be null),
* and possibly a comment (may be null), was encountered */
public void cell(String cellReference, String formattedValue, XSSFComment comment);
/** A header or footer has been encountered */
public void headerFooter(String text, boolean isHeader, String tagName);
/** Signal that the end of a sheet was been reached */
public void endSheet();
}
}

View File

@ -151,15 +151,9 @@ public class XSSFBEventBasedExcelExtractor extends XSSFEventBasedExcelExtractor
}
return text.toString();
} catch (IOException e) {
} catch (IOException | OpenXML4JException | SAXException e) {
LOGGER.log(POILogger.WARN, e);
return null;
} catch (SAXException se) {
LOGGER.log(POILogger.WARN, se);
return null;
} catch (OpenXML4JException o4je) {
LOGGER.log(POILogger.WARN, o4je);
return null;
}
}

View File

@ -178,7 +178,7 @@ public class XSSFEventBasedExcelExtractor extends POIXMLTextExtractor
/**
* Concatenate text from <rPh> text elements in SharedStringsTable
* Default is true;
* @param concatenatePhoneticRuns
* @param concatenatePhoneticRuns true if runs should be concatenated, false otherwise
*/
public void setConcatenatePhoneticRuns(boolean concatenatePhoneticRuns) {
this.concatenatePhoneticRuns = concatenatePhoneticRuns;
@ -293,15 +293,9 @@ public class XSSFEventBasedExcelExtractor extends POIXMLTextExtractor
}
return text.toString();
} catch(IOException e) {
} catch(IOException | OpenXML4JException | SAXException e) {
LOGGER.log(POILogger.WARN, e);
return null;
} catch(SAXException se) {
LOGGER.log(POILogger.WARN, se);
return null;
} catch(OpenXML4JException o4je) {
LOGGER.log(POILogger.WARN, o4je);
return null;
}
}
@ -348,6 +342,10 @@ public class XSSFEventBasedExcelExtractor extends POIXMLTextExtractor
output.append('\n');
}
@Override
public void endSheet() {
}
@Override
public void cell(String cellRef, String formattedValue, XSSFComment comment) {
if(firstCellOfRow) {