i want to fill an excel file and so i use ExcelPackage: Office Open XML Format . but i have an error. my code:
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();
}
i have this error in here: xlPackage.Save();
my error says that Object reference not set to an instance of an object.
when i take out xlPackage.Save();
, it works and fills in the excel file but it does not save.
why am i taking this error?
thanks in advance..
xlPackage
itself is not null since you use it before. So please post the entire Stack Trace as it's something internal in theExcelWorksheet
class. – RefractometerNullReferenceException
? – Scuba