Skip to content

System.InvalidCastException" when populating worksheet with List<MyModel> raised on SaveAs() #2477

@beatbesmer

Description

@beatbesmer

Do you want to request a feature or report a bug?

  • Bug
  • Feature
  • Question

Did you test against the latest CI build?

  • Yes
  • No

I don't have enough experience to test the latest CI build. I'm currently using the latest version available through the NuGet package manager.

Version of ClosedXML

Reproduced with 0.102.3 and 0.104.1

What is the current behavior?

The current behavior is that a System.InvalidCastException: 'Specified cast is not valid.' is thrown when trying to assign a decimal value to a cell in a worksheet). This happens when generating multiple worksheets from a List. The exception occurs even if I assign a fixed value like 0 to the cell. The issue only arises when calling SaveAs() on the workbook.

Question
I would like to know how to validate the (decimal)value of the fields or data before executing the SaveAs() method to prevent the System.InvalidCastException error.
I couldn't find anything related to this in the documentation. Additionally, attempting to cast the decimal values to double did not resolve the issue, which is strange since 95% of the list works fine with decimal

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions