Applying this simple diff to the test project, on the beta and on the current HEAD (90cfd9a3a979) reading the column before and after inserting, causes this exception on trying to access the newly created column:
```
Test method EPPlusTest.WorkSheetTest.RunWorksheetTests threw exception:
System.Exception: ColumnMax can not span over existing column 1.
at OfficeOpenXml.ExcelColumn.set_ColumnMax(Int32 value) in ExcelColumn.cs: line 90
at OfficeOpenXml.ExcelWorksheet.CopyColumn(ExcelColumn c, Int32 col, Int32 maxCol) in ExcelWorksheet.cs: line 1499
at OfficeOpenXml.ExcelWorksheet.Column(Int32 col) in ExcelWorksheet.cs: line 1466
at EPPlusTest.WorkSheetTest.InsertDeleteTestColumns() in WorkSheet.cs: line 421
at EPPlusTest.WorkSheetTest.RunWorksheetTests() in WorkSheet.cs: line 26
```
```
diff --git a/EPPlusTest/WorkSheet.cs b/EPPlusTest/WorkSheet.cs
index 5fb4938..2eec6c8 100644
--- a/EPPlusTest/WorkSheet.cs
+++ b/EPPlusTest/WorkSheet.cs
@@ -411,8 +411,15 @@ public void InsertDeleteTestColumns()
Assert.AreEqual(((object[,])ws.Cells["A1:C5"].Value)[1, 1], 1);
ws.Cells["A1:B3"].Merge = true;
ws.Cells["D3"].Formula = "A2+C5";
+
+ // Read column one before inserting
+ var colOriginal = ws.Column(1);
+
ws.InsertColumn(1, 1);
+ // Access the new column 1
+ var colNew = ws.Column(1);
+
ws.Cells["K10:M15"].Value = 1;
ws.Cells["K11:L13"].Merge = true;
ws.DeleteColumn(12, 1);
```
I've hit this in a production project so any intermediate advice to tweak it would be greatly welcomed!
Comments: I've developed a patch that appears to fix the problem, at least in my use cases. It's a bit brute force, but is attached, for reference. 1. I re-assign the column max and mins for all columns where these are the same 2. I handle the case where PrevCell returns a cell covering a range higher than that of the column (previously, only the maximum edge of the column definition was tested)
```
Test method EPPlusTest.WorkSheetTest.RunWorksheetTests threw exception:
System.Exception: ColumnMax can not span over existing column 1.
at OfficeOpenXml.ExcelColumn.set_ColumnMax(Int32 value) in ExcelColumn.cs: line 90
at OfficeOpenXml.ExcelWorksheet.CopyColumn(ExcelColumn c, Int32 col, Int32 maxCol) in ExcelWorksheet.cs: line 1499
at OfficeOpenXml.ExcelWorksheet.Column(Int32 col) in ExcelWorksheet.cs: line 1466
at EPPlusTest.WorkSheetTest.InsertDeleteTestColumns() in WorkSheet.cs: line 421
at EPPlusTest.WorkSheetTest.RunWorksheetTests() in WorkSheet.cs: line 26
```
```
diff --git a/EPPlusTest/WorkSheet.cs b/EPPlusTest/WorkSheet.cs
index 5fb4938..2eec6c8 100644
--- a/EPPlusTest/WorkSheet.cs
+++ b/EPPlusTest/WorkSheet.cs
@@ -411,8 +411,15 @@ public void InsertDeleteTestColumns()
Assert.AreEqual(((object[,])ws.Cells["A1:C5"].Value)[1, 1], 1);
ws.Cells["A1:B3"].Merge = true;
ws.Cells["D3"].Formula = "A2+C5";
+
+ // Read column one before inserting
+ var colOriginal = ws.Column(1);
+
ws.InsertColumn(1, 1);
+ // Access the new column 1
+ var colNew = ws.Column(1);
+
ws.Cells["K10:M15"].Value = 1;
ws.Cells["K11:L13"].Merge = true;
ws.DeleteColumn(12, 1);
```
I've hit this in a production project so any intermediate advice to tweak it would be greatly welcomed!
Comments: I've developed a patch that appears to fix the problem, at least in my use cases. It's a bit brute force, but is attached, for reference. 1. I re-assign the column max and mins for all columns where these are the same 2. I handle the case where PrevCell returns a cell covering a range higher than that of the column (previously, only the maximum edge of the column definition was tested)