此源代码:
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();
}
我在xlpackage.save i.e. object reference not set to an instance.
如何使用Excel模板生成包含多页的excel文件?