You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2009/05/17 20:49:30 UTC
svn commit: r775738 - in /poi/trunk/src:
documentation/content/xdocs/changes.xml
documentation/content/xdocs/status.xml
java/org/apache/poi/hssf/extractor/ExcelExtractor.java
ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java
Author: nick
Date: Sun May 17 18:49:29 2009
New Revision: 775738
URL: http://svn.apache.org/viewvc?rev=775738&view=rev
Log:
Tweaked patch from bug #46287 - Control of header and footer extraction in ExcelExtractor / XSSFExcelExtractor
Modified:
poi/trunk/src/documentation/content/xdocs/changes.xml
poi/trunk/src/documentation/content/xdocs/status.xml
poi/trunk/src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java
poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java
Modified: poi/trunk/src/documentation/content/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/changes.xml?rev=775738&r1=775737&r2=775738&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/changes.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/changes.xml Sun May 17 18:49:29 2009
@@ -37,6 +37,7 @@
<!-- Don't forget to update status.xml too! -->
<release version="3.5-beta6" date="2009-??-??">
+ <action dev="POI-DEVELOPERS" type="add">46287 - Control of header and footer extraction in ExcelExtractor / XSSFExcelExtractor</action>
<action dev="POI-DEVELOPERS" type="add">46554 - New ant target "jar-examples"</action>
<action dev="POI-DEVELOPERS" type="add">46161 - Support in XSSF for setGroupColumnCollapsed and setGroupRowCollapsed</action>
<action dev="POI-DEVELOPERS" type="add">46806 - Allow columns greater than 255 and rows greater than 0x100000 in XSSF formulas</action>
Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=775738&r1=775737&r2=775738&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Sun May 17 18:49:29 2009
@@ -34,6 +34,7 @@
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.5-beta6" date="2009-??-??">
+ <action dev="POI-DEVELOPERS" type="add">46287 - Control of header and footer extraction in ExcelExtractor / XSSFExcelExtractor</action>
<action dev="POI-DEVELOPERS" type="add">46554 - New ant target "jar-examples"</action>
<action dev="POI-DEVELOPERS" type="add">46161 - Support in XSSF for setGroupColumnCollapsed and setGroupRowCollapsed</action>
<action dev="POI-DEVELOPERS" type="add">46806 - Allow columns greater than 255 and rows greater than 0x100000 in XSSF formulas</action>
Modified: poi/trunk/src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java?rev=775738&r1=775737&r2=775738&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java Sun May 17 18:49:29 2009
@@ -55,6 +55,7 @@
private boolean _shouldEvaluateFormulas = true;
private boolean _includeCellComments = false;
private boolean _includeBlankCells = false;
+ private boolean _includeHeadersFooters = true;
public ExcelExtractor(HSSFWorkbook wb) {
super(wb);
@@ -79,6 +80,7 @@
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;
@@ -87,6 +89,7 @@
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)) {
@@ -127,6 +130,10 @@
showBlankCells = parseBoolArg(args, ++i);
continue;
}
+ if ("--headers-footers".equals(arg)) {
+ headersFooters = parseBoolArg(args, ++i);
+ continue;
+ }
throw new CommandParseException("Invalid argument '" + arg + "'");
}
_requestHelp = requestHelp;
@@ -135,6 +142,7 @@
_evaluateFormulas = evaluateFormulas;
_showCellComments = showCellComments;
_showBlankCells = showBlankCells;
+ _headersFooters = headersFooters;
}
private static boolean parseBoolArg(String[] args, int i) throws CommandParseException {
if (i >= args.length) {
@@ -167,7 +175,9 @@
public boolean shouldShowBlankCells() {
return _showBlankCells;
}
-
+ public boolean shouldIncludeHeadersFooters() {
+ return _headersFooters;
+ }
}
private static void printUsageMessage(PrintStream ps) {
@@ -180,6 +190,7 @@
ps.println(" --evaluate-formulas Y");
ps.println(" --show-comments N");
ps.println(" --show-blanks Y");
+ ps.println(" --headers-footers Y");
}
/**
@@ -216,6 +227,7 @@
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();
@@ -249,6 +261,13 @@
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
@@ -274,7 +293,7 @@
}
// Header text, if there is any
- if(sheet.getHeader() != null) {
+ if(_includeHeadersFooters && sheet.getHeader() != null) {
text.append(
_extractHeaderFooter(sheet.getHeader())
);
@@ -364,7 +383,7 @@
}
// Finally Feader text, if there is any
- if(sheet.getFooter() != null) {
+ if(_includeHeadersFooters && sheet.getFooter() != null) {
text.append(
_extractHeaderFooter(sheet.getFooter())
);
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java?rev=775738&r1=775737&r2=775738&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java Sun May 17 18:49:29 2009
@@ -40,6 +40,7 @@
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));
@@ -82,6 +83,12 @@
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
@@ -96,15 +103,17 @@
}
// 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) {
@@ -138,15 +147,17 @@
}
// 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();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org