Skip to Content

password protected Excel workbook

Hi,

I have a scenario that reads an Excel(using adapter module) and convert it into CSV file.

Now i need a solution to read a password protected workbook using Jexcel API.

Regards,

Bhanu.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Sep 14, 2009 at 05:27 AM

    try using

    
    abstract  boolean isProtected() 
              Determines whether the sheet is protected 
    
    public class PasswordException 
    extends BiffException 
    A properly typed exception in case consumers of the API specifically wish to handle the case when the workbook is password protected 
    
    Package jxl.read.biff
    
    

    refer API for more details

    Edited by: Kubra fatima on Sep 14, 2009 7:32 AM

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 14, 2009 at 05:42 AM
    With the help of JExcelApi, we can load a password protected Microsoft Excel spreadsheet into memory, 
    unprotect any protected sheets, and write back an unprotected copy back to disk
    
     following code fragment illustrates how to read a Microsoft Excel spreadsheet into memory, unprotect any protected sheets, 
    and write back an unprotected version of the Excel spreadsheet back to disk. 
    
    package net.ensode.jexcelapitest;
    
    import java.io.File;
    import java.io.IOException;
    
    import jxl.Workbook;
    import jxl.read.biff.BiffException;
    import jxl.write.WritableSheet;
    import jxl.write.WritableWorkbook;
    import jxl.write.WriteException;
    
    public class JExcelApiTest
    {
      public static void main(String[] args)
      {
        try
        {
          Workbook workbook = Workbook.
              getWorkbook(new File("/path/to/protected.xls"));
          WritableWorkbook copy = Workbook.
              createWorkbook(new File("/path/to/unprotected.xls"), workbook);
    
          WritableSheet[] sheets =  copy.getSheets();
    
          for (WritableSheet sheet : sheets)
          {
            sheet.getSettings().setProtected(false);
          }
    
          copy.write();
          copy.close();
        }
        catch (BiffException e)
        {
          e.printStackTrace();
        }
        catch (IOException e)
        {
          e.printStackTrace();
        }
        catch (WriteException e)
        {
          e.printStackTrace();
        }
    
      }
    
    }
    

    Add comment
    10|10000 characters needed characters exceeded