When adding a new protected range with following code:
```
ExcelProtectedRange protectedRange = mySheet.ProtectedRanges.Add("test", new ExcelAddress(2, 1, 4, 1));
```
the resulting file is corrupted. In particular the worksheet "mySheet".
The issue is that the XML element <protectedRanges> has to be before <autoFilter>. But it is appended as one of the last elements.
To fix this "ExcelWorksheet.cs" has to be modified.
Change code below:
```
public ExcelProtectedRangeCollection ProtectedRanges
{
get
{
if (_protectedRanges == null)
_protectedRanges = new ExcelProtectedRangeCollection(NameSpaceManager, TopNode, this);
return _protectedRanges;
}
}
```
to:
```
public ExcelProtectedRangeCollection ProtectedRanges
{
get
{
if (_protectedRanges == null)
{
_protectedRanges = new ExcelProtectedRangeCollection(NameSpaceManager, TopNode, this);
_protectedRanges.SchemaNodeOrder = SchemaNodeOrder;
}
return _protectedRanges;
}
}
```
```
ExcelProtectedRange protectedRange = mySheet.ProtectedRanges.Add("test", new ExcelAddress(2, 1, 4, 1));
```
the resulting file is corrupted. In particular the worksheet "mySheet".
The issue is that the XML element <protectedRanges> has to be before <autoFilter>. But it is appended as one of the last elements.
To fix this "ExcelWorksheet.cs" has to be modified.
Change code below:
```
public ExcelProtectedRangeCollection ProtectedRanges
{
get
{
if (_protectedRanges == null)
_protectedRanges = new ExcelProtectedRangeCollection(NameSpaceManager, TopNode, this);
return _protectedRanges;
}
}
```
to:
```
public ExcelProtectedRangeCollection ProtectedRanges
{
get
{
if (_protectedRanges == null)
{
_protectedRanges = new ExcelProtectedRangeCollection(NameSpaceManager, TopNode, this);
_protectedRanges.SchemaNodeOrder = SchemaNodeOrder;
}
return _protectedRanges;
}
}
```