Skip to content

[Bug ?] Trying to read a cell with a negative TimeSpan causes a FormatException #694

@lucas-mull

Description

@lucas-mull

Hello,

First of all, thank you for the work on this library which has been of great use to us.
That being said, I recently encountered an issue with negative timespans that prevents us to read a file.

Description of the issue

I have an XLSX file with a column formatted as follow:
image

As I understand it, ExcelDataReader handles these formats by converting them to TimeSpan internally.

The issue is that Excel allows negative values for this column, for instance:
image

When attempting to read a row with a negative timespan, the reader will attempt to call XmlConvert.ToTimeSpan(...) which will fail with a FormatException.

I could not find a way to bypass this conversion attempt without changing the format of the cell in the file directly, which is not ideal as those files are generated automatically by a third-party app on which we have no control.

Is this the intended behaviour ? As I understand it, c# TimeSpan cannot be negative, but I feel like since Excel allows it, those values should be handled in a different way (maybe simply by removing the sign or returning the raw string, i.e. dropping the conversion attempt altogether) ?

How to reproduce

Here is an example file:
negative_timespans.xlsx

Thanks for your help

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions