I am trying to create a new excel sheet(xlsx) from existing excel sheet(xlsx) using EPPlus. My existing excel sheet contains 4 worksheets and I want to update some cells in new excel sheet and save it in new location. Here is my code
public string RunSample22(DirectoryInfo outputDir) { FileInfo tempFile = new FileInfo(@"F:\bin\Debug\ReportTemplateFile.xlsx"); // Making a new file 'Sample2.xlsx' FileInfo newFile = new FileInfo(@"E:\Test" + @"\Sample22.xlsx"); if (newFile.Exists) { newFile.Delete(); newFile = new FileInfo(outputDir.FullName + @"\Sample22.xls"); } using (ExcelPackage package = new ExcelPackage(newFile, tempFile )) // getting error in this line { // Openning first Worksheet of the template file i.e. 'Sample1.xlsx' ExcelWorksheet worksheet = package.Workbook.Worksheets[1]; worksheet.Cells[1, 1].Value = "Test"; // Save our new workbook package.Save(); } return newFile.FullName; }
And Getting below error in my catch block. "File contains corrupted data." What I am missing or any suggestions.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)