https://issues.apache.org/bugzilla/show_bug.cgi?id=47074
--- Comment #1 from Kishore <[email protected]> 2009-04-22 07:19:27 PST --- The attached code is pasted below. package com.lehman.pcs.bcu.util; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import org.apache.poi.hssf.record.RecordFormatException; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.eventfilesystem.POIFSReader; import org.apache.poi.poifs.eventfilesystem.POIFSReaderEvent; import org.apache.poi.poifs.eventfilesystem.POIFSReaderListener; import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.POIFSDocumentPath; import org.apache.poi.poifs.filesystem.POIFSFileSystem; public class POIFSExtract { public static void main(String[] args) throws Exception { //if (args == null || args.length < 1) //throw new Exception("\n->no input, no output<-"); String fileName1 = "H:\\Kishor\\Research\\EmailWorkFlow\\Web_Server_Comparison.xls"; POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(fileName1)); POIFSReader reader = new POIFSReader(); reader.registerListener(new MyPOIFSReaderListener(fs)); reader.read(new FileInputStream(fileName1)); } static class MyPOIFSReaderListener implements POIFSReaderListener { private POIFSFileSystem fs; public MyPOIFSReaderListener(POIFSFileSystem fs) { this.fs = fs; } public void processPOIFSReaderEvent(POIFSReaderEvent event) { String name = event.getName(); POIFSDocumentPath path = event.getPath(); System.out.println("got '" + name + "' event for path '" + path + "'."); if (name.endsWith("Workbook") || name.endsWith("WORKBOOK")) { try { DirectoryNode dir = resolveDir(fs, event.getPath().toString()); // converting it to DirectoryNode System.out.println(" trying DirectoryNode '" + dir.getName() + "'"); HSSFWorkbook wb = new HSSFWorkbook(dir, fs, true); //invoke HSSFWorkbook constructor passing this directory to it System.out.println(" !!! success: workbook with " + wb.getNumberOfSheets() + " sheets."); } catch (RecordFormatException e) { // MS Graph charts are stored in "Workbook" stream too System.out.println(" skipping embedded MS Graph object!"); } catch (Exception e) { System.out.println(" " + e.getMessage()); throw new RuntimeException(e.getMessage()); } } } static DirectoryNode resolveDir(POIFSFileSystem filesystem, String path) throws FileNotFoundException { DirectoryNode dir = filesystem.getRoot(); for (String token : path.split("\\" + File.separator)) { if (!token.equals("") && !token.equals(File.separator)) dir = (DirectoryNode) dir.getEntry(token); } return dir; } } } -- Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
