private boolean _shouldEvaluateFormulas = true;
private boolean _includeCellComments = false;
private boolean _includeBlankCells = false;
+ private boolean _includeHeadersFooters = true;
public ExcelExtractor(HSSFWorkbook wb) {
super(wb);
private final boolean _evaluateFormulas;
private final boolean _showCellComments;
private final boolean _showBlankCells;
+ private final boolean _headersFooters;
public CommandArgs(String[] args) throws CommandParseException {
int nArgs = args.length;
File inputFile = null;
boolean evaluateFormulas = true;
boolean showCellComments = false;
boolean showBlankCells = false;
+ boolean headersFooters = true;
for (int i=0; i<nArgs; i++) {
String arg = args[i];
if ("-help".equalsIgnoreCase(arg)) {
showBlankCells = parseBoolArg(args, ++i);
continue;
}
+ if ("--headers-footers".equals(arg)) {
+ headersFooters = parseBoolArg(args, ++i);
+ continue;
+ }
throw new CommandParseException("Invalid argument '" + arg + "'");
}
_requestHelp = requestHelp;
_evaluateFormulas = evaluateFormulas;
_showCellComments = showCellComments;
_showBlankCells = showBlankCells;
+ _headersFooters = headersFooters;
}
private static boolean parseBoolArg(String[] args, int i) throws CommandParseException {
if (i >= args.length) {
public boolean shouldShowBlankCells() {
return _showBlankCells;
}
-
+ public boolean shouldIncludeHeadersFooters() {
+ return _headersFooters;
+ }
}
private static void printUsageMessage(PrintStream ps) {
ps.println(" --evaluate-formulas Y");
ps.println(" --show-comments N");
ps.println(" --show-blanks Y");
+ ps.println(" --headers-footers Y");
}
/**
extractor.setFormulasNotResults(!cmdArgs.shouldEvaluateFormulas());
extractor.setIncludeCellComments(cmdArgs.shouldShowCellComments());
extractor.setIncludeBlankCells(cmdArgs.shouldShowBlankCells());
+ extractor.setIncludeHeadersFooters(cmdArgs.shouldIncludeHeadersFooters());
System.out.println(extractor.getText());
} catch (Exception e) {
e.printStackTrace();
public void setIncludeBlankCells(boolean includeBlankCells) {
_includeBlankCells = includeBlankCells;
}
+ /**
+ * Should headers and footers be included in the output?
+ * Default is to include them.
+ */
+ public void setIncludeHeadersFooters(boolean includeHeadersFooters) {
+ _includeHeadersFooters = includeHeadersFooters;
+ }
/**
* Retrieves the text contents of the file
}
// Header text, if there is any
- if(sheet.getHeader() != null) {
+ if(_includeHeadersFooters && sheet.getHeader() != null) {
text.append(
_extractHeaderFooter(sheet.getHeader())
);
}
// Finally Feader text, if there is any
- if(sheet.getFooter() != null) {
+ if(_includeHeadersFooters && sheet.getFooter() != null) {
text.append(
_extractHeaderFooter(sheet.getFooter())
);
private boolean includeSheetNames = true;
private boolean formulasNotResults = false;
private boolean includeCellComments = false;
+ private boolean includeHeadersFooters = true;
public XSSFExcelExtractor(String path) throws XmlException, OpenXML4JException, IOException {
this(new XSSFWorkbook(path));
public void setIncludeCellComments(boolean includeCellComments) {
this.includeCellComments = includeCellComments;
}
+ /**
+ * Should headers and footers be included? Default is true
+ */
+ public void setIncludeHeadersFooters(boolean includeHeadersFooters) {
+ this.includeHeadersFooters = includeHeadersFooters;
+ }
/**
* Retreives the text contents of the file
}
// Header(s), if present
- text.append(
- extractHeaderFooter(sheet.getFirstHeader())
- );
- text.append(
- extractHeaderFooter(sheet.getOddHeader())
- );
- text.append(
- extractHeaderFooter(sheet.getEvenHeader())
- );
+ if(includeHeadersFooters) {
+ text.append(
+ extractHeaderFooter(sheet.getFirstHeader())
+ );
+ text.append(
+ extractHeaderFooter(sheet.getOddHeader())
+ );
+ text.append(
+ extractHeaderFooter(sheet.getEvenHeader())
+ );
+ }
// Rows and cells
for (Object rawR : sheet) {
}
// Finally footer(s), if present
- text.append(
- extractHeaderFooter(sheet.getFirstFooter())
- );
- text.append(
- extractHeaderFooter(sheet.getOddFooter())
- );
- text.append(
- extractHeaderFooter(sheet.getEvenFooter())
- );
+ if(includeHeadersFooters) {
+ text.append(
+ extractHeaderFooter(sheet.getFirstFooter())
+ );
+ text.append(
+ extractHeaderFooter(sheet.getOddFooter())
+ );
+ text.append(
+ extractHeaderFooter(sheet.getEvenFooter())
+ );
+ }
}
return text.toString();