use of org.apache.poi.poifs.filesystem.NPOIFSFileSystem in project poi by apache.
the class OutlookTextExtactor method main.
public static void main(String[] args) throws Exception {
for (String filename : args) {
NPOIFSFileSystem poifs = null;
OutlookTextExtactor extractor = null;
try {
poifs = new NPOIFSFileSystem(new File(filename));
extractor = new OutlookTextExtactor(poifs);
System.out.println(extractor.getText());
} finally {
if (extractor != null)
extractor.close();
if (poifs != null)
poifs.close();
}
}
}
use of org.apache.poi.poifs.filesystem.NPOIFSFileSystem in project poi by apache.
the class TestBugs method bug51461.
/**
* File with exactly 256 data blocks (+header block)
* shouldn't break on POIFS loading
*/
@SuppressWarnings("resource")
@Test
public void bug51461() throws Exception {
byte[] data = HSSFITestDataProvider.instance.getTestDataFileContent("51461.xls");
HSSFWorkbook wbPOIFS = new HSSFWorkbook(new POIFSFileSystem(new ByteArrayInputStream(data)).getRoot(), false);
HSSFWorkbook wbNPOIFS = new HSSFWorkbook(new NPOIFSFileSystem(new ByteArrayInputStream(data)).getRoot(), false);
assertEquals(2, wbPOIFS.getNumberOfSheets());
assertEquals(2, wbNPOIFS.getNumberOfSheets());
}
use of org.apache.poi.poifs.filesystem.NPOIFSFileSystem in project poi by apache.
the class TestBugs method bug46904.
/**
* java.io.IOException: block[ 0 ] already removed
* (is an excel 95 file though)
*/
@Test
public void bug46904() throws Exception {
try {
OPOIFSFileSystem fs = new OPOIFSFileSystem(HSSFITestDataProvider.instance.openWorkbookStream("46904.xls"));
new HSSFWorkbook(fs.getRoot(), false).close();
fail("Should catch exception here");
} catch (OldExcelFormatException e) {
assertTrue(e.getMessage().startsWith("The supplied spreadsheet seems to be Excel"));
}
try {
NPOIFSFileSystem fs = new NPOIFSFileSystem(HSSFITestDataProvider.instance.openWorkbookStream("46904.xls"));
try {
new HSSFWorkbook(fs.getRoot(), false).close();
fail("Should catch exception here");
} finally {
fs.close();
}
} catch (OldExcelFormatException e) {
assertTrue(e.getMessage().startsWith("The supplied spreadsheet seems to be Excel"));
}
}
use of org.apache.poi.poifs.filesystem.NPOIFSFileSystem in project poi by apache.
the class TestBugs method bug51535.
/**
* Large row numbers and NPOIFS vs POIFS
*/
@SuppressWarnings("resource")
@Test
public void bug51535() throws Exception {
byte[] data = HSSFITestDataProvider.instance.getTestDataFileContent("51535.xls");
HSSFWorkbook wbPOIFS = new HSSFWorkbook(new POIFSFileSystem(new ByteArrayInputStream(data)).getRoot(), false);
HSSFWorkbook wbNPOIFS = new HSSFWorkbook(new NPOIFSFileSystem(new ByteArrayInputStream(data)).getRoot(), false);
for (HSSFWorkbook wb : new HSSFWorkbook[] { wbPOIFS, wbNPOIFS }) {
assertEquals(3, wb.getNumberOfSheets());
// Check directly
HSSFSheet s = wb.getSheetAt(0);
assertEquals("Top Left Cell", s.getRow(0).getCell(0).getStringCellValue());
assertEquals("Top Right Cell", s.getRow(0).getCell(255).getStringCellValue());
assertEquals("Bottom Left Cell", s.getRow(65535).getCell(0).getStringCellValue());
assertEquals("Bottom Right Cell", s.getRow(65535).getCell(255).getStringCellValue());
// Extract and check
ExcelExtractor ex = new ExcelExtractor(wb);
String text = ex.getText();
assertContains(text, "Top Left Cell");
assertContains(text, "Top Right Cell");
assertContains(text, "Bottom Left Cell");
assertContains(text, "Bottom Right Cell");
ex.close();
}
}
use of org.apache.poi.poifs.filesystem.NPOIFSFileSystem in project poi by apache.
the class HWPFDocument method write.
/**
* Writes out the word file that is represented by an instance of this class.
*
* If the {@link File} exists, it will be replaced, otherwise a new one
* will be created
*
* @param newFile The File to write to.
* @throws IOException If there is an unexpected IOException from writing
* to the File.
*
* @since 3.15 beta 3
*/
@Override
public void write(File newFile) throws IOException {
NPOIFSFileSystem pfs = POIFSFileSystem.create(newFile);
write(pfs, true);
pfs.writeFilesystem();
}
Aggregations