0

I'm using EPPluse to work with Excel.

Following is my code.

using (ExcelPackage package = new ExcelPackage(fileInfo))
        {
            ExcelWorksheet worksheet = package.Workbook.Worksheets[1];
            int noofQuotas = 0;//no of row per group should be added
            int headingTemplateStartingRow = 47;
            int headingTemplateEndingRow = 50;
            int headerStartingRowId = 47;//starting row of group table heading 
            int headerEndingRowId = 50; //last row of group table heading
            int insertbefore = 51;//last row of default excel      
            int NoOfcolumnsToCopy = 30;
            int gapBetweenGroups = 2;
            worksheet.DeleteRow(51, 2, true);
            foreach (AnswerEstimateGroup obj in Groups)
            {

                noofQuotas = obj.Quotas.Count;
                //copy the header from group 1
                int totalrows = worksheet.Dimension.Rows;
                worksheet.Cells[headingTemplateStartingRow, 1, headingTemplateEndingRow, NoOfcolumnsToCopy].Copy(worksheet.Cells[headerStartingRowId, 1, headerEndingRowId, NoOfcolumnsToCopy]);
                foreach (Quota qobj in obj.Quotas)
                {
                    worksheet.InsertRow(insertbefore, 1);
                }
                worksheet.InsertRow(insertbefore, gapBetweenGroups);
                headerStartingRowId = headerEndingRowId + noofQuotas + gapBetweenGroups;
                headerEndingRowId = headerStartingRowId + 4;
                insertbefore = headerEndingRowId + 1;
                worksheet.InsertRow(insertbefore,20);

                package.Save();
            }
        }

In for loop, I'm able to copy rows but for the second time, I'm getting an error.

enter image description here

i couldnt figure out what went wron

  • Possible duplicate of [What is an IndexOutOfRangeException / ArgumentOutOfRangeException and how do I fix it?](https://stackoverflow.com/questions/20940979/what-is-an-indexoutofrangeexception-argumentoutofrangeexception-and-how-do-i-f) – VDWWD Aug 30 '18 at 09:30
  • Note that in Excel indexes start at `1`, not `0` – VDWWD Aug 30 '18 at 09:53

0 Answers0