Start on bug 45540, not fixed yet though

git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@682655 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2008-08-05 09:50:05 +00:00
parent 6b2768f4d7
commit 1acb09f9bd
8 changed files with 50 additions and 9 deletions

View File

@ -19,11 +19,9 @@ package org.apache.poi.hssf.extractor;
import java.io.IOException;
import org.apache.poi.POIOLE2TextExtractor;
import org.apache.poi.hssf.usermodel.HeaderFooter;
import org.apache.poi.ss.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;
@ -95,7 +93,7 @@ public class ExcelExtractor extends POIOLE2TextExtractor {
// Header text, if there is any
if(sheet.getHeader() != null) {
text.append(
extractHeaderFooter(sheet.getHeader())
_extractHeaderFooter(sheet.getHeader())
);
}
@ -168,7 +166,7 @@ public class ExcelExtractor extends POIOLE2TextExtractor {
// Finally Feader text, if there is any
if(sheet.getFooter() != null) {
text.append(
extractHeaderFooter(sheet.getFooter())
_extractHeaderFooter(sheet.getFooter())
);
}
}
@ -176,7 +174,7 @@ public class ExcelExtractor extends POIOLE2TextExtractor {
return text.toString();
}
private String extractHeaderFooter(HeaderFooter hf) {
public static String _extractHeaderFooter(HeaderFooter hf) {
StringBuffer text = new StringBuffer();
if(hf.getLeft() != null) {

View File

@ -20,8 +20,10 @@ import java.io.IOException;
import java.util.Iterator;
import org.apache.poi.POIXMLTextExtractor;
import org.apache.poi.hssf.extractor.ExcelExtractor;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Comment;
import org.apache.poi.ss.usermodel.HeaderFooter;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
@ -94,6 +96,13 @@ public class XSSFExcelExtractor extends POIXMLTextExtractor {
text.append(workbook.getSheetName(i) + "\n");
}
// Header, if present
if(sheet.getHeader() != null) {
text.append(
extractHeaderFooter(sheet.getHeader())
);
}
for (Object rawR : sheet) {
Row row = (Row)rawR;
for(Iterator<Cell> ri = row.cellIterator(); ri.hasNext();) {
@ -123,8 +132,19 @@ public class XSSFExcelExtractor extends POIXMLTextExtractor {
}
text.append("\n");
}
// Finally footer, if present
if(sheet.getFooter() != null) {
text.append(
extractHeaderFooter(sheet.getFooter())
);
}
}
return text.toString();
}
private String extractHeaderFooter(HeaderFooter hf) {
return ExcelExtractor._extractHeaderFooter(hf);
}
}

View File

@ -17,12 +17,11 @@
package org.apache.poi.xssf.usermodel.extensions;
import org.apache.poi.ss.usermodel.Footer;
import org.apache.poi.ss.usermodel.HeaderFooter;
import org.apache.poi.xssf.usermodel.helpers.HeaderFooterHelper;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
public abstract class XSSFHeaderFooter implements Footer{
public abstract class XSSFHeaderFooter implements HeaderFooter {
private HeaderFooterHelper helper;
private CTHeaderFooter headerFooter;
private String value;

View File

@ -188,4 +188,28 @@ public class TestXSSFExcelExtractor extends TestCase {
assertTrue(m.matches());
}
}
/**
* From bug #45540
*/
public void BROKENtestHeaderFooter() throws Exception {
String[] files = new String[] {
"45540_classic_Footer.xlsx", "45540_form_Footer.xlsx",
"45540_classic_Header.xlsx", "45540_form_Header.xlsx"
};
for(String file : files) {
File xml = new File(
System.getProperty("HSSF.testdata.path") +
File.separator + file
);
assertTrue(xml.exists());
XSSFExcelExtractor extractor =
new XSSFExcelExtractor(new XSSFWorkbook(xml.toString()));
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"));
}
}
}