public ActionResult Excel2(int? id)
{
List<TBL_Table1> FileData = db.TBL_Table1.Where(x => x.Tableid == id).ToList();
string DosyaAdi = "";
try
{
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
var existingFilePath = Server.MapPath("~/App_Data/IsBasvuru2.xlsx");
var existingFile = new FileInfo(existingFilePath);
using (var memoryStream = new MemoryStream())
{
using (var excelPackage = new ExcelPackage(existingFile))
{
var worksheet = excelPackage.Workbook.Worksheets[0]; // İlk çalışma sayfasını aç
foreach (var data in FileData)
{
//worksheet.Cells["D7"].Value = data.GenelBilgiid;
worksheet.Cells["P21"].Value = data.Ad;
worksheet.Cells["AN21"].Value = data.Soyad;
DosyaAdi = data.Ad + "-" + data.Soyad + "-" + data.GenelBilgiid + ".xlsx";
worksheet.Cells["AN25"].Value = data.DogumYeri;
worksheet.Cells["P25"].Value = Convert.ToDateTime(data.DogumTarihi).ToShortDateString();
}
excelPackage.SaveAs(memoryStream);
}
memoryStream.Position = 0;
return File(memoryStream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", DosyaAdi);
}
}
catch (Exception ex)
{
return new ContentResult { Content = "Excel dosyası oluşturulurken bir hata oluştu: " + ex.Message };
}
}
Hello everyone, friends, I have a question for you, I can create an excel file with this code, it works very healthy, but I need to convert this file to pdf, that is, it will save the data in the excel file and convert all the pages in the excel file to pdf, can you help me with this?