Summary: | Excel 2007 unable to read the Excel file content. But the same file working fine after manual open and re-save the excel file. | ||
---|---|---|---|
Product: | POI | Reporter: | Prakash <prakash.chakravarthi> |
Component: | XSSF | Assignee: | POI Developers List <dev> |
Status: | RESOLVED FIXED | ||
Severity: | critical | ||
Priority: | P2 | ||
Version: | 3.13-FINAL | ||
Target Milestone: | --- | ||
Hardware: | PC | ||
OS: | All | ||
Attachments: | Attached the Standalone Java code to display the sheet name for the 2 different template file names. |
Description
Prakash
2015-11-16 21:10:44 UTC
I could make it work by adding the following BEFORE the call to dfs.getDataStream(): dec.verifyPassword(null); Can you verify if this makes it work for you as well? 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(); } } } ==================================================================================== This exception indicates that the file that you try to process is not an actual xlsx-file. The XLSX-Formatted files are actually zip-files with XML-files inside. Can you check if this is the case? Maybe you actually have an .xls (older Excel file format) file that has an incorrect file extension? Hi Dominik, Thanks for the analysis. I also tries to open it in the ZIP files extractor it doesn't extract. Its giving the file damaged/ corrupted. For the noraml working version of the apache POI extract the xlsx file by the zip extractor and read the content. Now the unknown areas was the same file opened by the Windows office and is their any way Apache POI can support to open this file problematically. Thanks, Prakash Sorry but I do not really understand your last comment, can you describe again what works and what not? Maybe by providing a sample XLSX file and the java code that you use to test it? FYI, the NullPointerException which was initially reported here should be fixed via r1722406 I think the original issues reported here have been fixed since some time and there was no response on the last questions for a long time. Please report new issues if there is still anything that looks like a bug. |