File XLWorkbook_Save.cs
Line 2222
Creation of RowLabels
```
var f = new Field {Index = pt.Fields.IndexOf(xlpf)};
```
Line 2240
```
var f = new Field {Index = pt.Fields.IndexOf(xlpf)};
```
The index of RowLabels and ColumnLabels is not correct because it is based on the order of Fields Collection
Is it correct changing the code in this way?
```
var f = new Field {Index = pt.RowLabels.IndexOf(pt.RowLabels.FirstOrDefault(p => p.SourceName == xlpf.SourceName))};
```
```
var f = new Field { Index = pt.ColumnLabels.IndexOf(pt.ColumnLabels.FirstOrDefault(p => p.SourceName == xlpf.SourceName)) };
```
Comments: How do I reproduce the problem? Here's the IndexOf method: public int IndexOf(IXLPivotField pf) { var selectedItem = _pivotFields.Select((item, index) => new {Item = item, Position = index}).FirstOrDefault(i => i.Item.Key == pf.SourceName); if (selectedItem == null) throw new IndexOutOfRangeException("Invalid field name."); return selectedItem.Position; }
Line 2222
Creation of RowLabels
```
var f = new Field {Index = pt.Fields.IndexOf(xlpf)};
```
Line 2240
```
var f = new Field {Index = pt.Fields.IndexOf(xlpf)};
```
The index of RowLabels and ColumnLabels is not correct because it is based on the order of Fields Collection
Is it correct changing the code in this way?
```
var f = new Field {Index = pt.RowLabels.IndexOf(pt.RowLabels.FirstOrDefault(p => p.SourceName == xlpf.SourceName))};
```
```
var f = new Field { Index = pt.ColumnLabels.IndexOf(pt.ColumnLabels.FirstOrDefault(p => p.SourceName == xlpf.SourceName)) };
```
Comments: How do I reproduce the problem? Here's the IndexOf method: public int IndexOf(IXLPivotField pf) { var selectedItem = _pivotFields.Select((item, index) => new {Item = item, Position = index}).FirstOrDefault(i => i.Item.Key == pf.SourceName); if (selectedItem == null) throw new IndexOutOfRangeException("Invalid field name."); return selectedItem.Position; }