use of org.apache.poi.poifs.filesystem.DirectoryNode in project poi by apache.
the class TestHSSFWorkbook method differentPOIFS.
/**
* Tests that we can work with both {@link POIFSFileSystem}
* and {@link NPOIFSFileSystem}
*/
@Test
public void differentPOIFS() throws Exception {
// Open the two filesystems
DirectoryNode[] files = new DirectoryNode[2];
POIFSFileSystem poifsFileSystem = new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream("Simple.xls"));
try {
files[0] = poifsFileSystem.getRoot();
NPOIFSFileSystem npoifsFileSystem = new NPOIFSFileSystem(HSSFTestDataSamples.getSampleFile("Simple.xls"));
try {
files[1] = npoifsFileSystem.getRoot();
// Open without preserving nodes
for (DirectoryNode dir : files) {
HSSFWorkbook workbook = new HSSFWorkbook(dir, false);
HSSFSheet sheet = workbook.getSheetAt(0);
HSSFCell cell = sheet.getRow(0).getCell(0);
assertEquals("replaceMe", cell.getRichStringCellValue().getString());
workbook.close();
}
// Now re-check with preserving
for (DirectoryNode dir : files) {
HSSFWorkbook workbook = new HSSFWorkbook(dir, true);
HSSFSheet sheet = workbook.getSheetAt(0);
HSSFCell cell = sheet.getRow(0).getCell(0);
assertEquals("replaceMe", cell.getRichStringCellValue().getString());
workbook.close();
}
} finally {
npoifsFileSystem.close();
}
} finally {
poifsFileSystem.close();
}
}
use of org.apache.poi.poifs.filesystem.DirectoryNode in project poi by apache.
the class TestNonStandardWorkbookStreamNames method testWrite.
/**
* Test that when we write out, we go back to the correct case
*/
@Test
public void testWrite() throws IOException {
for (String file : new String[] { xlsA, xlsB }) {
// Open the workbook, not preserving nodes
InputStream is = HSSFTestDataSamples.openSampleFileStream(file);
HSSFWorkbook wb = new HSSFWorkbook(is, false);
is.close();
// Check now it can be opened
HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb);
wb.close();
DirectoryNode root = wb2.getDirectory();
// Check that we have the new entries
assertTrue(root.hasEntry("Workbook"));
assertFalse(root.hasEntry("BOOK"));
assertFalse(root.hasEntry("WORKBOOK"));
wb2.close();
}
}
Aggregations