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

Free Support Forum - aspose.com

How to insert formula in the few cells and lock it down?

Dear Team,

I have requirement where we need to export data into excel along with formula for few cells and lock it down. Which properties do I need to set for them ?

I am using Aspose.Cell for .NET dll.

Thanks in advance,


Thanks for using Aspose APIs.

We will look into this issue and help you asap.

Thanks Shakeel for your acknowledgement. Just to add, I am using the version for the same.


Thanks for using Aspose APIs.

Please see the following document for your reference.


Please also try the following code. It unlocks cells B5, C5 and D5 where D5 contains formula. If you double click any cell other than these three cells, Microsoft Excel will prompt a warning message that cells are protected.

Please see the output Excel file generated by the code for your reference.

Download Link:
Output Excel File.zip (5.8 KB)


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

//Access first worksheet
Worksheet ws = wb.Worksheets[0];

//Put some values in cells
ws.Cells["D5"].Formula = "=Sum(B5,C5)";

//Calculate workbook

//Unlock the cells B5, C5, D5
Cell c = ws.Cells["B5"];
Style s = c.GetStyle();
s.IsLocked = false;


//Set protection that we allow selecting unlocked cells only
ws.Protection.AllowSelectingUnlockedCell = true;

//Protect the worksheet

//Save the output Excel file

Thanks Shakeel :slight_smile: