Hi,
My template contains 1 edit ranges (Name : Range1, Columns D and E are "allow to edit ranges" enabled.
This is my code:
Workbook workbook = new Workbook();
string templateFileName = Environment.CurrentDirectory + "\\ProtectSheetTemplate.xls";
workbook.Open(templateFileName);
Worksheet worksheet = workbook.Worksheets[0];
foreach (AllowEditRange range in worksheet.AllowEditRanges)
{
Console.WriteLine(range.Name);
Console.WriteLine(range.Password);
Console.WriteLine(range.CellArea.StartRow);
Console.WriteLine(range.CellArea.StartColumn);
Console.WriteLine(range.CellArea.EndRow);
Console.WriteLine(range.CellArea.EndColumn);
}
// Add range
int idx = worksheet.AllowEditRanges.Add("MyEditRange", 1, 1, 3, 3);
AllowEditRange myEditRange = worksheet.AllowEditRanges[idx];
myEditRange.Password = "edit";
foreach (AllowEditRange range in worksheet.AllowEditRanges)
{
Console.WriteLine(range.Name);
Console.WriteLine(range.Password);
Console.WriteLine(range.CellArea.StartRow);
Console.WriteLine(range.CellArea.StartColumn);
Console.WriteLine(range.CellArea.EndRow);
Console.WriteLine(range.CellArea.EndColumn);
}
worksheet.Protection.Password = "sheet";
worksheet.Protection.IsSelectingLockedCellsAllowed = true;
worksheet.Protection.IsSelectingUnlockedCellsAllowed = true;
worksheet.Protection.IsDeletingColumnsAllowed = false;
worksheet.Protection.IsDeletingRowsAllowed = false;
worksheet.Protection.IsEditingContentsAllowed = false;
worksheet.Protection.IsEditingObjectsAllowed = true;
worksheet.Protection.IsEditingScenariosAllowed = true;
worksheet.Protection.IsFormattingCellsAllowed = true;
worksheet.Protection.IsFormattingColumnsAllowed = true;
worksheet.Protection.IsFormattingRowsAllowed = true;
worksheet.Protection.IsInsertingColumnsAllowed = false;
worksheet.Protection.IsInsertingHyperlinksAllowed = false;
worksheet.Protection.IsInsertingRowsAllowed = false;
worksheet.Protection.IsFilteringAllowed = true;
worksheet.Protection.IsSortingAllowed = true;
worksheet.Protection.IsUsingPivotTablesAllowed = false;
workbook.Save(Environment.CurrentDirectory + "\\ProtectSheet.xls", FileFormatType.Excel97To2003);
It does not enter in the first foreach loop.
The output file does not contain anymore "Edit Ranges" (in Excel Application)
Thanks