EPPlus错误文件包含损坏的数据 [英] EPPlus Error File contains corrupted data
问题描述
我正在尝试 创建一个新的Excel工作表(xlsx )来自现有的Excel工作表(xlsx)使用 EPPlus。
我现有的Excel工作表包含 4 工作表和我希望 update 单元 新的Excel工作表和 save 新位置。
这里 我的代码
这篇关于EPPlus错误文件包含损坏的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
< pre lang =c#> public string RunSample22(DirectoryInfo outputDir)
{
FileInfo tempFile = new FileInfo( @ F:\\ \\bin\Debug\ReportTemplateFile.xlsx跨度>);
// 制作新文件'Sample2.xlsx'
FileInfo newFile = new FileInfo( @ E:\\ \\ Test + @ \ Sample22.xlsx);
if (newFile.Exists)
{
newFile.Delete();
newFile = new FileInfo(outputDir.FullName + @ \Sample22.xls跨度>);
}
使用(ExcelPackage package = new ExcelPackage(newFile ,tempFile)) // 在此行中收到错误
{
// 打开模板文件的第一个工作表,即'Sample1.xlsx'
ExcelWorksheet工作表=包。 Workbook.Worksheets [ 1 ];
worksheet.Cells [ 1 , 1 ]。值= 测试;
// 保存我们的新工作簿
package.Save( );
}
return newFile.FullName;
}
和在
我的catch块中获得以下错误。
文件包含损坏的数据。
我缺少的是或 任何建议。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.