Password Security Settings for Excel 2003 and later versions at workbook and sheet levels

Hi,

We checked in the Aspose.cells documentation, that workbook and worksheet can be protected using a password for MS Excel 2000 and earlier versions.But, can we do the same for MS Excel 2003 and later vesrions using Aspose.cells for java.

Any help on this is highly appreciated.

Regards,

Richa


This message was posted using Page2Forum from Protecting Worksheets - Aspose.Cells for Java

Hi,

Aspose.Cells for Java does support to protect workbooks and worksheets for MS Excel 2003 version. Please check the documents for reference (the code segments provided there in these documents would work fine for the Excel versions (XP - 2003) etc.):
http://www.aspose.com/documentation/java-components/aspose.cells-for-java/protecting-worksheets.html
http://www.aspose.com/documentation/java-components/aspose.cells-for-java/advanced-protection-settings-since-excel-xp.html
http://www.aspose.com/documentation/java-components/aspose.cells-for-java/encrypting-files.html


If you find any issue, kindly let us know.

Thank you.

Hi ,

Thanks for the prompt response.

One more thing i want to confirm, whether we can protect a particular cell using Aspose.cells...I tried using the code snippet given here:

http://www.aspose.com/documentation/java-components/aspose.cells-for-java/protecting-worksheets.html

but, it seems to protect the whole worksheet(all the cells) instead of a particular cell.

Thanks!

Richa

Hi,

The answer is already there in the document:
http://www.aspose.com/documentation/java-components/aspose.cells-for-java/protecting-worksheets.html

Check the sub-topic “Protect a few Cells in the Worksheet” in the document for your reference. The code segment there will protect only three cells i.e. A1,B1 and C1 in the worksheet. So, you may delete the following lines from the segment:

style
= sheet.getCells().getCell(
“B1”).getStyle();


style.setCellLocked(true);


style
= sheet.getCell(
“C1”).getStyle();


style.setCellLocked(true);

so, now only A1 cell would be protected in the whole worksheet.

Kindly let us know if you still find any issue regarding this.

Thank you.

Hi ,

Thanks for the reply..

But , I want to know what is the difference between cell and sheet protection done by Aspose.cell.Because, Cell protection here makes all the cells read only instead of the specified cell in the code(equivalent to sheet protection)...And once I unprotect the sheet, I dont see any protected cell.

Could you please assist...

Thanks!

Richa

Hi,

Sorry for the confusion.

Please try the following code, if you are using the latest versions of the product (v2.1.2 or greater versions), you need to do add this subtle change in the code, see the following lines of code, it will protect A1 cell only in the whole worksheet.

// Create a new workbook.
Workbook wb = new Workbook();

// Create a worksheet object and obtain the first sheet.
Worksheet sheet = wb.getWorksheets().getSheet(0);

// Define the style object.
Style style;

// Loop through all the columns in the worksheet and unlock them.
for(int i = 0; i <= 255; i ++)
{

style = sheet.getCells().getColumns().getColumn(i).getStyle();
style.setCellLocked(false);
sheet.getCells().getColumns().getColumn(i).setStyle(style);

}



// Lock the the cell…i.e. A1.
style = sheet.getCells().getCell(“A1”).getStyle();
style.setCellLocked(true);
sheet.getCells().getCell(“A1”).setStyle(style);

// Finally, Protect the sheet now.
Protection protection = new Protection();
sheet.protect(protection);

// Save the excel file.
wb.save(“d:\files\lockedcells.xls”, FileFormatType.EXCELXP);


For reference of the new change, see the release notes i.e. “Notable changes for users:” :
http://www.aspose.com/community/files/72/java-components/aspose.cells-for-java/entry221865.aspx


We will soon update the sample codes in the document too.

Thank you.


Hi,

It did work for me.Thanks for your supports.

Regards,

Richa