cancel
Showing results for 
Search instead for 
Did you mean: 

password protected Excel workbook

former_member556412
Active Participant
0 Kudos

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.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

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();
    }

  }

}

Former Member
0 Kudos

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