We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com


Hi There,

I am evaluating Aspose Cell for our client’s need, and wanted to
know below thing if its possible.

is this possible that i dont allow use to unprotect the
worksheet, as well as lock all columns other then 2 or 3 in
which user can do changes?

I am seeking for .Net code or samples if you can provide?

Thanks in advance.

This message was posted using Email2Forum by msabir.


I think you should Password protect your Worksheets in the Excel workbook. This way, only who knows the password can unprotect the sheet(s). I don’t think there is any option that prevents or disable unprotect option in MS Excel, if you know let us know, we can look into it.

For locking all columns other than 2,3 etc., please see the document on how you may do it:
(Note: please see the sub-topics int he document: “Protect a Column in the Worksheet” and “Allow Users to Edit Ranges” in special).

Also, see the topic on how you may set advanced protecting options in MS Excel:

Also, if you need to encrypt an Excel (you may set password even to open an Excel file for your need), see the document:

Thank you.

Hi Amjad,

Thanks for the quick reply. What my ultimate goal is,

1) want to allow all users to download the data in excel sheet (so i will import my data into excel sheet which is pre formatted)

2) with that downloaded excel, i want all those users to update only few column's contents only and nothing else.

3) I archieved with un-locking the range of cells, keeping all other locked, but the issue with that is, end user can un-protect whole sheet and can update all rest of the columns which i dont want

4) Just to let you know, i then want that excel sheet to be imported back to the database. So if user has modified those columns which i dont want, will mess up my requirements.

Did i make you clear why i dont want users to un-protect my excel sheet?

Thanks again.


1) See the document on how you may import data from DataTable or other sources:

2) See the sample code on how you may password protect all the columns in the sheet except B and C column:
Sample code:

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

// Create a worksheet object and obtain the first sheet.
Worksheet sheet = wb.Worksheets[0];

// Define the style object.
Style style;

// Define the styleflag object.
StyleFlag flag;

// Loop through B and C columns in the worksheet and unlock them.
for (int i = 1; i < 3; i++)
style = sheet.Cells.Columns[(byte)i].Style;
style.IsLocked = false;
flag = new StyleFlag();
flag.Locked = true;
sheet.Cells.Columns[(byte)i].ApplyStyle(style, flag);


// Protect the sheet with a password
// Doing so, it will lock all the cells in the sheet except B and C column
sheet.Protect(ProtectionType.All, “123”, null);

// Save the excel file.
wb.Save(“e:\test2\out_lockedcolumn.xls”, SaveFormat.Excel97To2003);

If you use Excel 2007 file formats, you can also try ProtectedRangeCollection API

3) As I said earlier, there is no options available in MS Excel which can disable Unprotect option for the users if the worksheet is protected. I know, let us know with template file and steps involved in MS Excel (by manually created in MS Excel). We can check it soon

4) I think you may export your worksheet data to fill a datatable or array, then you may use your own code to save it back to you data source.

Thank you.