tags:

views:

17

answers:

1

Hi all,

using (ExcelPackage xlPackage = new ExcelPackage(newFile, template))
{
  ExcelWorksheet worksheet = null;
  foreach (DataTable dt in dsExcel.Tables)
  {
    worksheet = xlPackage.Workbook.Worksheets.Add(dt.TableName);
    worksheet = xlPackage.Workbook.Worksheets[dt.TableName];
    ExcelCell cell;
    const int startRow = 9;
    int row = startRow;
    int col = 1;
    foreach (DataRow dr in dt.Rows)
    {
      foreach (DataColumn dc in dt.Columns)
      {
        worksheet.Cell(row, col).Value = dr[dc].ToString();
        col++;
      }
      col = 1;
      row++;
    }
  }
  xlPackage.Save();
}

I am getting error at xlpackage.save i.e. object reference not set to an instance.

please help me in it .

how to generate an excel file with multiplesheets using an excel template.

A: 

Looks like this is a bug, documented here. Unfortunately, it looks like the fix is to edit the source code of ExcelPackage itself.

Mark