use of org.apache.poi.poifs.filesystem.NPOIFSFileSystem in project poi by apache.
the class TestChartTitleFormatRecord method testRecord.
@Test
public void testRecord() throws Exception {
NPOIFSFileSystem fs = new NPOIFSFileSystem(HSSFTestDataSamples.getSampleFile("WithFormattedGraphTitle.xls"));
// Check we can open the file via usermodel
HSSFWorkbook hssf = new HSSFWorkbook(fs);
// Now process it through eventusermodel, and
// look out for the title records
ChartTitleFormatRecordGrabber grabber = new ChartTitleFormatRecordGrabber();
InputStream din = fs.createDocumentInputStream("Workbook");
HSSFRequest req = new HSSFRequest();
req.addListenerForAllRecords(grabber);
HSSFEventFactory factory = new HSSFEventFactory();
factory.processEvents(req, din);
din.close();
// Should've found one
assertEquals(1, grabber.chartTitleFormatRecords.size());
// And it should be of something interesting
ChartTitleFormatRecord r = grabber.chartTitleFormatRecords.get(0);
assertEquals(3, r.getFormatCount());
hssf.close();
fs.close();
}
use of org.apache.poi.poifs.filesystem.NPOIFSFileSystem in project poi by apache.
the class TestXorEncryption method testUserFile.
@SuppressWarnings("static-access")
@Test
public void testUserFile() throws IOException {
Biff8EncryptionKey.setCurrentUserPassword("abc");
NPOIFSFileSystem fs = new NPOIFSFileSystem(samples.getSampleFile("xor-encryption-abc.xls"), true);
HSSFWorkbook hwb = new HSSFWorkbook(fs.getRoot(), true);
HSSFSheet sh = hwb.getSheetAt(0);
assertEquals(1.0, sh.getRow(0).getCell(0).getNumericCellValue(), 0.0);
assertEquals(2.0, sh.getRow(1).getCell(0).getNumericCellValue(), 0.0);
assertEquals(3.0, sh.getRow(2).getCell(0).getNumericCellValue(), 0.0);
hwb.close();
fs.close();
}
use of org.apache.poi.poifs.filesystem.NPOIFSFileSystem in project poi by apache.
the class TestHSSFWorkbook method testRewriteFileBug58480.
@Test
public void testRewriteFileBug58480() throws IOException {
final File file = TempFile.createTempFile("TestHSSFWorkbook", ".xls");
try {
// create new workbook
{
final Workbook workbook = new HSSFWorkbook();
final Sheet sheet = workbook.createSheet("foo");
final Row row = sheet.createRow(1);
row.createCell(1).setCellValue("bar");
writeAndCloseWorkbook(workbook, file);
}
// edit the workbook
{
NPOIFSFileSystem fs = new NPOIFSFileSystem(file, false);
try {
DirectoryNode root = fs.getRoot();
final Workbook workbook = new HSSFWorkbook(root, true);
final Sheet sheet = workbook.getSheet("foo");
sheet.getRow(1).createCell(2).setCellValue("baz");
writeAndCloseWorkbook(workbook, file);
} finally {
fs.close();
}
}
} finally {
assertTrue(file.exists());
assertTrue(file.delete());
}
}
use of org.apache.poi.poifs.filesystem.NPOIFSFileSystem in project poi by apache.
the class TestHSSFWorkbook method closeDoesNotModifyWorkbook.
@Test
public void closeDoesNotModifyWorkbook() throws IOException {
final String filename = "SampleSS.xls";
final File file = POIDataSamples.getSpreadSheetInstance().getFile(filename);
Workbook wb;
// File via POIFileStream (java.io)
wb = new HSSFWorkbook(new POIFSFileSystem(file));
assertCloseDoesNotModifyFile(filename, wb);
// File via NPOIFileStream (java.nio)
wb = new HSSFWorkbook(new NPOIFSFileSystem(file));
assertCloseDoesNotModifyFile(filename, wb);
// InputStream
wb = new HSSFWorkbook(new FileInputStream(file));
assertCloseDoesNotModifyFile(filename, wb);
}
use of org.apache.poi.poifs.filesystem.NPOIFSFileSystem in project poi by apache.
the class BaseTestSlideShowFactory method testFactoryFromNative.
@SuppressWarnings("resource")
protected static void testFactoryFromNative(String file) throws Exception {
SlideShow<?, ?> ss;
// from NPOIFS
if (file.endsWith(".ppt")) {
NPOIFSFileSystem npoifs = new NPOIFSFileSystem(fromFile(file));
ss = SlideShowFactory.create(npoifs);
assertNotNull(ss);
npoifs.close();
assertCloseDoesNotModifyFile(file, ss);
} else // from OPCPackage
if (file.endsWith(".pptx")) {
// not implemented
throw new UnsupportedOperationException("Test not implemented");
} else {
fail("Unexpected file extension: " + file);
}
}
Aggregations