我一直在尝试让以下简单的代码工作,但它会引发和异常using (var excelPackage = new ExcelPackage(finfo))
string filepath = Convert.ToString(Dts.Variables["User::FileFullPath"].Value);
if (File.Exists(filepath))
{
FileInfo finfo = new FileInfo(filepath);
MessageBox.Show(filepath);
try
{
using (var excelPackage = new ExcelPackage(finfo))
{
ExcelWorksheet ws = excelPackage.Workbook.Worksheets[0];
ws.Name = "Sheet1";
excelPackage.Save();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.StackTrace, "Error", MessageBoxButtons.OK);
Dts.Events.FireError(1, "Check File Status", ex.StackTrace, "", 0);
}
Dts.TaskResult = (int)ScriptResults.Success;
}
else
{
Dts.TaskResult = (int)ScriptResults.Failure;
}
错误是:
通过注释掉一些行,我发现错误using (var excelPackage = new ExcelPackage(finfo))
在线。有人可以告诉我在这里做错了什么,或者如何更好地获得更详细的异常吗?