This project has moved and is read-only. For the latest updates, please go here.

InsertRow, Copy worked not correct

May 20 at 9:42 PM
Edited May 21 at 5:23 PM
Why is this happening ?

There is row pattern B2:F2

Cell B2 = "Text"
Cell C2 = "Text"
Cell D2:E2 is merged = "Text"
Cell F2 = "Text"

If this is done without "method IinsertRow", it works correctly and the row template is copied as necessary (including merged cells )
 using (ExcelPackage pkg = new ExcelPackage(new FileInfo(@"c:\input.xlsx")))
            {
                // correct work
                var ws = pkg.Workbook.Worksheets[1];
                var pattern = ws.Cells["B2:F2"];
                pattern.Copy(ws.Cells["B3:F3"]);
                pattern.Copy(ws.Cells["B4:F4"]);
                pattern.Copy(ws.Cells["B5:F5"]);
                pkg.SaveAs(new FileInfo(@"c:\output.xlsx"));
            }
            using (ExcelPackage pkg = new ExcelPackage(new FileInfo(@"c:\input.xlsx")))
            {
                // not correct work
                var ws = pkg.Workbook.Worksheets[1];
                // add three rows
                ws.InsertRow(2, 3);
                // go to pattern row after insert
                var pattern1 = ws.Cells["B5:F5"];
                // all is good here
                pattern1.Copy(ws.Cells["B2:F2"]);
                pattern1.Copy(ws.Cells["B3:F3"]); // Exception: Can't delete merged cells. A range is partly merged with the deleted range. D5:E5
                pkg.SaveAs(new FileInfo(@"c:\output.xlsx"));
            }
In this case (below), merged cells correct copied only in row= 2.
Why?
 using (ExcelPackage pkg = new ExcelPackage(new FileInfo(@"c:\input.xlsx")))
            {
                var ws = pkg.Workbook.Worksheets[1];
                var startRow = 2;
                var rowCount = 5;
                ws.InsertRow(startRow, rowCount);
                var copyRow = startRow+rowCount;
                for (int i = 0; i < rowCount; i++)
                {
                    var row = startRow + i;
                    ws.Cells[copyRow, 2, copyRow, ws.Dimension.End.Column].Copy(ws.Cells[row, 2, row, ws.Dimension.End.Column]);
                    ws.Row(row).StyleID = ws.Row(copyRow).StyleID;
                }
                pkg.SaveAs(new FileInfo(@"c:\output.xlsx"));
            }
What am I doing wrong ?
I need to use the methods InsertRow and Copy together.

ps. Used lastest EPPlus version via Nuget
May 23 at 7:05 PM
downloaded the latest build, problem solved!
I apologize...