https://bz.apache.org/bugzilla/show_bug.cgi?id=58616

--- Comment #2 from Prakash <prakash.chakravar...@schawk.com> ---
Hi Dominik,

Thanks for your help. 

By adding the dec.verifyPassword(null); before the dfs.getDataStream();
resolves that particular line issue. But its giving the "error in opening zip
file"  wb = new XSSFWorkbook(fileLocation);.

Can you please help to resolve this issue. The expected output for this jave
code to read that Excel sheet and print the SheetName.

Please find below the details error message after adding the line
dec.verifyPassword(null); as suggested by you in the previous comments.


==================================================================================
FileLocation:C:\ExcelProb\B4Save.xlsx
org.apache.poi.openxml4j.exceptions.InvalidOperationException: Can't open the
specified file: 'C:\ExcelProb\B4Save.xlsx'
    at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:112)
    at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:225)
    at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:187)
    at org.apache.poi.POIXMLDocument.openPackage(POIXMLDocument.java:84)
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:318)
    at StandAloneExcel.main(StandAloneExcel.java:40)
Caused by: java.util.zip.ZipException: error in opening zip file
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.<init>(Unknown Source)
    at java.util.zip.ZipFile.<init>(Unknown Source)
    at java.util.zip.ZipFile.<init>(Unknown Source)
    at
org.apache.poi.openxml4j.util.ZipSecureFile.<init>(ZipSecureFile.java:105)
    at
org.apache.poi.openxml4j.opc.internal.ZipHelper.openZipFile(ZipHelper.java:175)
    at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:110)
    ... 5 more


====================================================================================
Java code
====================================================================================
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import org.apache.poi.poifs.crypt.Decryptor;
import org.apache.poi.poifs.crypt.EncryptionInfo;
import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;


public class StandAloneExcel {

    /**
     * @param args
     */
//     public static String excelfilename = "C:\\ExcelProb\\AfterSave.xlsx";
     public static String excelfilename = "C:\\ExcelProb\\B4Save.xlsx";


    public static void main(String[] args) {

        XSSFWorkbook wb;
        XSSFSheet sheet;
        POIFSFileSystem pfs;
        String fileLocation;

        fileLocation=excelfilename;
        System.out.println("FileLocation:"+fileLocation);

        try{

                pfs = new POIFSFileSystem(new FileInputStream(fileLocation));   
                EncryptionInfo info = new EncryptionInfo(pfs);               
                Decryptor dec = Decryptor.getInstance(info);    

                dec.verifyPassword(null);
                dec.getDataStream(pfs);

                wb = new XSSFWorkbook(fileLocation);                
                sheet = wb.getSheetAt(0);               
                System.out.println("Sheet  Name"+ sheet.getSheetName());

        }catch(OfficeXmlFileException e){
            try{
                e.printStackTrace();
            wb = new XSSFWorkbook(new FileInputStream(fileLocation));           
            sheet = wb.getSheetAt(0);            
             System.out.println("Sheet  Name"+ sheet.getSheetName());

            }catch(FileNotFoundException ex)
            {
                ex.printStackTrace();
                System.out.println(" Exception:" + ex);


            }
            catch(Exception ex){
                ex.printStackTrace();
            }
        }catch(Exception e){
            e.printStackTrace();

        }

    }

}

====================================================================================

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@poi.apache.org
For additional commands, e-mail: dev-h...@poi.apache.org

Reply via email to