我正在使用EPPluse与Excel配合使用。
以下是我的代码。
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();
}
}
在for循环中,我能够复制行,但是第二次出现错误。
我不知道到底发生了什么