EPPlus 抛出 DataValidations 异常“请求的值‘日期’”没有找到。”当尝试保存 xlsm 时

发布于 2024-12-18 08:55:23 字数 1447 浏览 1 评论 0原文

我正在尝试使用 EPPlus。

但是在 package.Save(name) 或 packagae.SaveAs(name) 上,DataValidations 集合会抛出异常:

2011-11-28 14:17:51,380 [9] ERROR app.ExcelConverter - System.ArgumentException: Requested value 'date' was not found.
   at System.Enum.EnumResult.SetFailure(ParseFailureKind failure, String failureMessageID, Object failureMessageFormatArgument)
   at System.Enum.TryParseEnum(Type enumType, String value, Boolean ignoreCase, EnumResult& parseResult)
   at System.Enum.Parse(Type enumType, String value, Boolean ignoreCase)
   at OfficeOpenXml.DataValidation.ExcelDataValidationCollection..ctor(ExcelWorksheet worksheet)
   at OfficeOpenXml.ExcelWorksheet.get_DataValidations()
   at FItoExcelCore.ExcelConverter.RunSample(String filePath) in \path\to\class.cs:line 32

即使尝试worksheet.DataValidations.Clear() 抛出相同的异常,并且这没有对文件进行任何更改:

        try
        {
            using (ExcelPackage package = new ExcelPackage(output))
            {
                package.SaveAs(output);
            }
        }
        catch (Exception ex)
        {
            _log.Error(ex.ToString());
        }

我在从头开始创建的 Excel 文件中没有此行为,但我需要使用提供的文件。

不知道它是否重要,但我正在使用 .Net 4 Framework,并且它是一个 1.01 MB 的 .xlsm 文件。文件在 Excel 中保存/保存(即使有新数据)。

注意:显然 .xlsx 文件工作得很好,但是 .xlsm 格式包含无法保存为 .xlsx 格式的 VBA 宏,因此无法转换文件类型。

I'm attempting to make changes to a customer-supplied .xlsm file (a C# application will fill with data from a web-form and submit to a CMS) using EPPlus.

But on package.Save(name) -- or packagae.SaveAs(name) -- an exception is thrown by the DataValidations collection:

2011-11-28 14:17:51,380 [9] ERROR app.ExcelConverter - System.ArgumentException: Requested value 'date' was not found.
   at System.Enum.EnumResult.SetFailure(ParseFailureKind failure, String failureMessageID, Object failureMessageFormatArgument)
   at System.Enum.TryParseEnum(Type enumType, String value, Boolean ignoreCase, EnumResult& parseResult)
   at System.Enum.Parse(Type enumType, String value, Boolean ignoreCase)
   at OfficeOpenXml.DataValidation.ExcelDataValidationCollection..ctor(ExcelWorksheet worksheet)
   at OfficeOpenXml.ExcelWorksheet.get_DataValidations()
   at FItoExcelCore.ExcelConverter.RunSample(String filePath) in \path\to\class.cs:line 32

Even attempting worksheet.DataValidations.Clear() throws the same exception, and this is without any changes to the file:

        try
        {
            using (ExcelPackage package = new ExcelPackage(output))
            {
                package.SaveAs(output);
            }
        }
        catch (Exception ex)
        {
            _log.Error(ex.ToString());
        }

I do not have this behavior in an excel file that I create from scratch, but I need to use the supplied file.

Don't know if it's significant, but I'm working in the .Net 4 Framework, and it's an 1.01 MB .xlsm file. The file saves/saves-as fine (even with new data) from within Excel.

NOTE: apparently .xlsx files work just fine, but the the .xlsm format contain VBA macros that can't be saved in the .xlsx format, so the file-type cannot be converted.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

江南月 2024-12-25 08:55:23

像往常一样,在发布后六十秒内,我在网上找到了新信息。

EPPlus codeplex 网站上有一个讨论,表明“没有真正的支持对于组件中的 [xlsm 文件]。

这可能是问题的根源。

As usual, within sixty seconds of posting I find new information online.

There is a discussion at the EPPlus codeplex site that suggests that "there is no real support for [xlsm files] in the component."

The may be the source of the problem.

↙温凉少女 2024-12-25 08:55:23

您有最新版本的 EPPlus 吗?

他们于 2011 年 3 月修复了这个问题。这与 ValidationTypes 不区分大小写有关。

看:
http://epplus.codeplex.com/workitem/13246

编辑 :
如果不支持 xlsm,您也可以尝试将其另存为 .xlsx。

Do you have the latest version of EPPlus?

They fixed this issue March of 2011. It had to do with ValidationTypes being case insensitive.

See:
http://epplus.codeplex.com/workitem/13246

Edit:
You can also try saving it as .xlsx if xlsm isn't supported.

暖心男生 2024-12-25 08:55:23

正如 Ed 所写,我已经下载了 EPPlus 的最新版本,即 2012 年 1 月 31 日发布的版本,它的验证效果非常好。读写的excel是.xlsx格式。

As Ed Wrote i have donwloaded the last version of EPPlus which is from Jan 31 2012,and it worked very well with its validation. The excel im reading and writting is a .xlsx format.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文