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

Free Support Forum - aspose.com

Protect worksheet but allow to hide rows

Hi,

In my excel worksheet, I want to protect the worksheet so that the user won't be able to change the entry in the locked cells. I manage to achieve this by using :

sheet.Protect(ProtectionType.Contents, "password","");

By using this, the cells will be locked, but it also prevents me to hide the rows while the sheet is protected. Is there any way to enable user to hide/unhide the rows while the sheet is still protected? How do I achieve that?

Thanks for your advise.

Hi,
I think you should make use of Advanced protection settings (ExcelXP - Excel2003)
May the following code help you for your need.
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";
wb.Save("d:\\test\\allowrowformattings.xls",FileFormatType.ExcelXP);

Thank you.

Hi,

Thanks for your reply.

Would this Advanced protection settings (ExcelXP - Excel2003) work for Excel 2000 ?

Regards,

Cecilia

No. MS Excel2000 doesn’t support this feature.