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.
i couldnt figure out what went wron