我想填补一个Excel文件,所以我使用ExcelPackage:的Office Open XML格式。 但我有一个错误。 我的代码:
string fileName = "DBE_BAKIM_FORMU" + ".xlsx";
FileInfo fi = new FileInfo(HttpContext.Current.Server.MapPath("~/") + fileName);
using (ExcelPackage xlPackage = new ExcelPackage(fi))
{
ExcelWorksheet worksheet = xlPackage.Workbook.Worksheets[1];
dbeDataContext db = new dbeDataContext();
CAGRI c = (from x in db.CAGRIs where x.CagriID == ID select x).SingleOrDefault();
USER u = (from x in db.USERs where x.UserID == Convert.ToInt32(Session["user"]) select x).SingleOrDefault();
worksheet.Cell(6, 3).Value = c.TalepTarihi.ToShortDateString();
worksheet.Cell(7, 3).Value = c.TalepTuru;
worksheet.Cell(8, 3).Value = c.ModulAdi;
worksheet.Cell(9, 3).Value = c.EkranRaporAdi;
worksheet.Cell(10, 3).Value = c.VerilenSure;
worksheet.Cell(11, 4).Value = c.USER.UserName + " " + c.USER.UserSurname;
worksheet.Cell(12, 4).Value = Convert.ToString(c.USER.UserTel);
worksheet.Cell(13, 3).Value = c.Aciklama;
worksheet.Cell(16, 4).Value = u.UserName + " " + u.UserSurname;
worksheet.Cell(18, 3).Value = Convert.ToString(c.DegerlendirmeTarih);
worksheet.Cell(19, 3).Value = c.Degerlendirme;
xlPackage.Save();
}
我有这样的错误在这里: xlPackage.Save();
我的错误说, Object reference not set to an instance of an object.
当我取出xlPackage.Save();
,它的工作原理,并在Excel文件罢了,但它不保存。 为什么我取这个错误?
提前致谢..