on 2009 Sep 14 4:47 AM
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.
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();
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
12 | |
10 | |
10 | |
10 | |
9 | |
8 | |
7 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.