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

Free Support Forum - aspose.com

Protect macro

How do I protect my macro inside the workbook via Aspose?
Also, I have a sheet with data (look ups etc…) can I hide it with a password?

Can I see these protections via Aspose?



Hi Ilan,

Thanks for considering Aspose.

How do I protect my macro inside the workbook via Aspose?
Currently, Aspose.Cells does not support to create or manage VBA macros, althought you may delete vba macros using Workbook.RemoveMacro() method. But if you could create VBA macros in your template file, Aspose.Cells supports to load the file with macros and save the workbook (Excel file) with vba / macros attached.

Also, I have a sheet with data (look ups etc...) can I hide it with a password?
Yes you may do it, You can protect a sheet with password and may also hide it.

Sample Example shows how to protect a sheet with some advanced options:

Workbook wb = new Workbook();
Worksheet sheet = wb.Worksheets[0];
Cells cells = wb.Worksheets[0].Cells;
for ( int row= 0; row<20;row++)
for(int col = 0;col<10;col++)
cells[row,col].PutValue(row.ToString() + "," + col.ToString());


sheet.Protection.IsDeletingColumnsAllowed = false;
sheet.Protection.IsDeletingRowsAllowed = false;
sheet.Protection.IsEditingContentsAllowed = false;
sheet.Protection.IsEditingObjectsAllowed = false;
sheet.Protection.IsEditingScenariosAllowed = false;
sheet.Protection.IsFilteringAllowed = false;
sheet.Protection.IsFormattingCellsAllowed = false;
sheet.Protection.IsFormattingColumnsAllowed = false;
//To allow row formattings
sheet.Protection.IsFormattingRowsAllowed = true;
sheet.Protection.IsInsertingColumnsAllowed = false;
sheet.Protection.IsInsertingHyperlinksAllowed = false;
sheet.Protection.IsInsertingRowsAllowed = false;
sheet.Protection.IsSelectingLockedCellsAllowed = true;
sheet.Protection.IsSelectingUnlockedCellsAllowed = true;
sheet.Protection.IsSortingAllowed = false;
sheet.Protection.IsUsingPivotTablesAllowed = false;
sheet.Protection.Password = "007";

For futher reference, please check the following wiki topics:

Thank you.