I am generating several excel copies from a template (its really big).
For that First I am taking the template from a file location, then based on a loop for every iteration I am creating a new ExcelPackage(newFile,Template)
.
After that I am taking the exact ExcelWorksheet
that I have to edit.
Then after editing I am Saving as the file as newFile. The time of opening the saved file Two problem is occurring:
- If there is no Excel instance is running on the PC then the saved file is opening but with no data.
If the Excel instance is running then the saved file is opening with Warning message but working. "Problem with some content with Excel. Do you want us to recover?" and "Excel was able to recover some unreadable content "
string templateExcel = @"Location\template.xlsx"; FileInfo templateFile = new FileInfo(@"Location\newFile.xlsx"); using (FileStream templateExcelStream = File.OpenRead(templateExcel)) { using (ExcelPackage copyExcel = new ExcelPackage(templateExcelStream)) { ExcelWorksheet presentWorkSheet = copyExcel.Workbook.Worksheets["Name"]; presentWorkSheet.Cells[4, 2].Value = Value from condition; copyExcel.SaveAs(templateFile); } }