I am trying to protect an Excel worksheet so that the user can select any cell(s), sort any cells, filter any cells but cannot modify the data in any way (delete columns or rows or edit cells.
Using API Mate, I come up with this code.
TSheetProtectionOptions SheetProtectionOptions;
SheetProtectionOptions = new TSheetProtectionOptions(false);
SheetProtectionOptions.Contents = true;
SheetProtectionOptions.Objects = true;
SheetProtectionOptions.Scenarios = true;
SheetProtectionOptions.SelectLockedCells = true;
SheetProtectionOptions.SortCellRange = true;
SheetProtectionOptions.EditAutoFilters = true;
SheetProtectionOptions.SelectUnlockedCells = true;
xls.Protection.SetSheetProtection("******", SheetProtectionOptions);
SheetProtectionOptions = new TSheetProtectionOptions(false);
SheetProtectionOptions.Contents = true;
SheetProtectionOptions.Objects = true;
SheetProtectionOptions.Scenarios = true;
SheetProtectionOptions.SelectLockedCells = true;
SheetProtectionOptions.SortCellRange = true;
SheetProtectionOptions.EditAutoFilters = true;
SheetProtectionOptions.SelectUnlockedCells = true;
xls.Protection.SetSheetProtection("******", SheetProtectionOptions);
However, when I actually create the worksbook, that sheet will not allow sorting or filtering.
Is this a bug or am I missing something? We are using Excel 2007 but I have also tested this with Excel 2003 and the results are the same.