<!-- Don't forget to update status.xml too! -->
<release version="3.1.1-alpha1" date="2008-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">45538 - Include excel headers and footers in the output of ExcelExtractor</action>
<action dev="POI-DEVELOPERS" type="fix">44894 - refactor duplicate logic from EventRecordFactory to RecordFactory</action>
<action dev="POI-DEVELOPERS" type="add">Support for Headers / Footers in HSLF</action>
<action dev="POI-DEVELOPERS" type="fix">44953 - Extensive fixes for data validation</action>
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.1.1-alpha1" date="2008-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">45538 - Include excel headers and footers in the output of ExcelExtractor</action>
<action dev="POI-DEVELOPERS" type="fix">44894 - refactor duplicate logic from EventRecordFactory to RecordFactory</action>
<action dev="POI-DEVELOPERS" type="add">Support for Headers / Footers in HSLF</action>
<action dev="POI-DEVELOPERS" type="fix">44953 - Extensive fixes for data validation</action>
import java.io.IOException;
import org.apache.poi.POIOLE2TextExtractor;
+import org.apache.poi.hssf.usermodel.HeaderFooter;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFComment;
+import org.apache.poi.hssf.usermodel.HSSFFooter;
+import org.apache.poi.hssf.usermodel.HSSFHeader;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
}
}
+ // Header text, if there is any
+ if(sheet.getHeader() != null) {
+ text.append(
+ extractHeaderFooter(sheet.getHeader())
+ );
+ }
+
int firstRow = sheet.getFirstRowNum();
int lastRow = sheet.getLastRowNum();
for(int j=firstRow;j<=lastRow;j++) {
// Finish off the row
text.append("\n");
}
+
+ // Finally Feader text, if there is any
+ if(sheet.getFooter() != null) {
+ text.append(
+ extractHeaderFooter(sheet.getFooter())
+ );
+ }
+ }
+
+ return text.toString();
+ }
+
+ private String extractHeaderFooter(HeaderFooter hf) {
+ StringBuffer text = new StringBuffer();
+
+ if(hf.getLeft() != null) {
+ text.append(hf.getLeft());
+ }
+ if(hf.getCenter() != null) {
+ if(text.length() > 0)
+ text.append("\t");
+ text.append(hf.getCenter());
+ }
+ if(hf.getRight() != null) {
+ if(text.length() > 0)
+ text.append("\t");
+ text.append(hf.getRight());
}
+ if(text.length() > 0)
+ text.append("\n");
return text.toString();
}
* <P>
* @author Shawn Laubach (slaubach at apache dot org)
*/
-public class HSSFFooter extends Object {
+public class HSSFFooter extends Object implements HeaderFooter {
FooterRecord footerRecord;
String left;
*
* @author Shawn Laubach (slaubach at apache dot org)
*/
-public class HSSFHeader
+public class HSSFHeader implements HeaderFooter
{
HeaderRecord headerRecord;
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.hssf.usermodel;
+
+/**
+ * Common interface for {@link HSSFHeader} and
+ * {@link HSSFFooter}.
+ */
+public interface HeaderFooter {
+ public String getLeft();
+ public void setLeft( String newLeft );
+
+ public String getCenter();
+ public void setCenter( String newCenter );
+
+ public String getRight();
+ public void setRight( String newRight );
+
+}
ex.getText());
assertEquals("Excel With Embeded", ex.getSummaryInformation().getTitle());
}
+
+ /**
+ * Test that we get text from headers and footers
+ */
+ public void test45538() throws Exception {
+ String[] files = new String[] {
+ "45538_classic_Footer.xls", "45538_form_Footer.xls",
+ "45538_classic_Header.xls", "45538_form_Header.xls"
+ };
+ for(int i=0; i<files.length; i++) {
+ ExcelExtractor extractor = createExtractor(files[i]);
+ String text = extractor.getText();
+ assertTrue("Unable to find expected word in text\n" + text, text.contains("testdoc"));
+ assertTrue("Unable to find expected word in text\n" + text, text.contains("test phrase"));
+ }
+ }
}