我想填写一个 excel 文件,所以我使用 ExcelPackage: Office Open XML Format 。但我有一个错误。我的代码:
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 文件,但不保存。为什么我会犯这个错误?
提前致谢..