0
votes

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.

3
an unanswered SO question also suggests that EPPlus doesn't work for xlsm files: stackoverflow.com/questions/6336803/…Michael Paulukonis

3 Answers

1
votes

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.

0
votes

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.

0
votes

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.