use of org.apache.poi.POITextExtractor in project poi by apache.
the class TestZipPackage method testZipEntityExpansionSharedStringTable.
@Test
public void testZipEntityExpansionSharedStringTable() throws Exception {
Workbook wb = WorkbookFactory.create(XSSFTestDataSamples.openSamplePackage("poc-shared-strings.xlsx"));
wb.close();
POITextExtractor extractor = ExtractorFactory.createExtractor(HSSFTestDataSamples.getSampleFile("poc-shared-strings.xlsx"));
try {
assertNotNull(extractor);
try {
extractor.getText();
} catch (IllegalStateException e) {
// expected due to shared strings expansion
}
} finally {
extractor.close();
}
}
use of org.apache.poi.POITextExtractor in project poi by apache.
the class TestXSSFEventBasedExcelExtractor method testComparedToOLE2.
/**
* Test that we return pretty much the same as
* ExcelExtractor does, when we're both passed
* the same file, just saved as xls and xlsx
*/
@Test
public void testComparedToOLE2() throws Exception {
// A fairly simple file - ooxml
XSSFEventBasedExcelExtractor ooxmlExtractor = getExtractor("SampleSS.xlsx");
ExcelExtractor ole2Extractor = new ExcelExtractor(HSSFTestDataSamples.openSampleWorkbook("SampleSS.xls"));
POITextExtractor[] extractors = new POITextExtractor[] { ooxmlExtractor, ole2Extractor };
for (POITextExtractor extractor : extractors) {
String text = extractor.getText().replaceAll("[\r\t]", "");
assertStartsWith(text, "First Sheet\nTest spreadsheet\n2nd row2nd row 2nd column\n");
Pattern pattern = Pattern.compile(".*13(\\.0+)?\\s+Sheet3.*", Pattern.DOTALL);
Matcher m = pattern.matcher(text);
assertTrue(m.matches());
}
ole2Extractor.close();
ooxmlExtractor.close();
}
use of org.apache.poi.POITextExtractor in project poi by apache.
the class TestXSSFExcelExtractor method testComparedToOLE2.
/**
* Test that we return pretty much the same as
* ExcelExtractor does, when we're both passed
* the same file, just saved as xls and xlsx
*/
public void testComparedToOLE2() throws IOException {
// A fairly simple file - ooxml
XSSFExcelExtractor ooxmlExtractor = getExtractor("SampleSS.xlsx");
ExcelExtractor ole2Extractor = new ExcelExtractor(HSSFTestDataSamples.openSampleWorkbook("SampleSS.xls"));
Map<String, POITextExtractor> extractors = new HashMap<String, POITextExtractor>();
extractors.put("SampleSS.xlsx", ooxmlExtractor);
extractors.put("SampleSS.xls", ole2Extractor);
for (final Entry<String, POITextExtractor> e : extractors.entrySet()) {
String filename = e.getKey();
POITextExtractor extractor = e.getValue();
String text = extractor.getText().replaceAll("[\r\t]", "");
assertStartsWith(filename, text, "First Sheet\nTest spreadsheet\n2nd row2nd row 2nd column\n");
Pattern pattern = Pattern.compile(".*13(\\.0+)?\\s+Sheet3.*", Pattern.DOTALL);
Matcher m = pattern.matcher(text);
assertTrue(filename, m.matches());
}
ole2Extractor.close();
ooxmlExtractor.close();
}
Aggregations