Results 1 to 3 of 3
  1. #1
    vijay7539 is offline Member
    Join Date
    Nov 2009
    Posts
    4
    Rep Power
    0

    Default Read pasword protected Excel file

    Hi Guys,

    How to read Password protected Excel file using java. Actually i read normal excel file(without password protection) successfully, using some standard coadings with support POI jars. But i am unable to read password protected xls file. Can you please tell me how to do that.

    Thanks for advance.

    regards
    Vijay

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    I'm not sure how to do this either. Though I remember having problems reading 'protected' sheets in excel files as well. What I used to do was use an older version of openoffice, that did not implement the page protection checking as complete as it is now, like it allowed you to edit a page that was protected to be read only if opened in excel and such.
    So i wonder if you were to first open the file in openoffice, or excel, and save-as it (such as without using password protection on the save as 'd version, would that work ?

  3. #3
    Join Date
    Aug 2014
    Posts
    2
    Rep Power
    0

    Default Re: Read pasword protected Excel file

    Hi With Apache POI it is possible to password protect an excel file. PFB for the code. But it is working with XLSX extension [2010 Excel format], But not with XLS [2003 Excel format]
    Can you please give an idea of how to accomplish the same

    package com.excel.utility;

    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.OutputStream;
    import java.security.GeneralSecurityException;

    import org.apache.poi.openxml4j.exceptions.InvalidFormatE xception;
    import org.apache.poi.openxml4j.opc.OPCPackage;
    import org.apache.poi.openxml4j.opc.PackageAccess;
    import org.apache.poi.poifs.crypt.EncryptionInfo;
    import org.apache.poi.poifs.crypt.EncryptionMode;
    import org.apache.poi.poifs.crypt.Encryptor;
    import org.apache.poi.poifs.filesystem.POIFSFileSystem;

    public class ReadPasswordProtectedXLSX {
    public static void main(String[] args) throws IOException,
    InvalidFormatException, GeneralSecurityException {

    // Add password protection and encrypt the file
    POIFSFileSystem fs = new POIFSFileSystem();
    EncryptionInfo info = new EncryptionInfo(fs, EncryptionMode.agile);

    Encryptor enc = info.getEncryptor();
    enc.confirmPassword("Password1");

    OPCPackage opc = OPCPackage.open(new File(
    "C:\\Users\\Desktop\\Book1.xlsx"),
    PackageAccess.READ_WRITE);
    OutputStream os = enc.getDataStream(fs);
    opc.save(os);
    opc.close();

    FileOutputStream fos = new FileOutputStream(
    "C:\\Users\\Desktop\\Book1.xlsx");
    fs.writeFilesystem(fos);
    fos.close();

    System.out.println("File created!!");
    }
    }

Similar Threads

  1. JXL read excel documents
    By ironicending in forum Java Applets
    Replies: 1
    Last Post: 09-08-2010, 12:42 AM
  2. Excel sheet opening in read-only mode
    By swati.jyoti in forum Advanced Java
    Replies: 2
    Last Post: 09-08-2009, 02:08 PM
  3. How to Read Excel file??
    By spalax in forum New To Java
    Replies: 3
    Last Post: 08-15-2009, 05:06 AM
  4. How to read Excel file with java
    By chetan-24 in forum New To Java
    Replies: 5
    Last Post: 04-22-2009, 05:11 PM
  5. How to read data from excel and store it in db
    By saran123 in forum New To Java
    Replies: 5
    Last Post: 10-03-2008, 10:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •