2

I have an excel file and I want to import its data to a web application using ClosedXML.

Now I am using this to read a date as string:

var validFrom = ((DateTime)row.Cell("B").Value).ToString("d/M/yyyy");

and this to read a decimal as string:

var price = row.Cell(letter).Value.ToString();

In order for this to work I have to copy paste-as-values-only from excel and then import the file to my app. Formulas contain filepaths from remote excel files that are not accessible from the server or function that are not working with ClosedXML (such as VLOOKUP).

How can I read data as displayed without re-evaluating the formula?

mike_x_
  • 1,900
  • 3
  • 35
  • 69
  • This behaviour will improve when https://github.com/ClosedXML/ClosedXML/pull/1058 is merged. Then you would be able to use the `.Value` property as expected. – Francois Botha Nov 03 '18 at 12:35
  • Sidenote, you might benefit from the `cell.GetDateTime()` and `cell.GetFormattedString()` methods. The current casting that you do seems a bit unnecessary. – Francois Botha Nov 03 '18 at 12:36

1 Answers1

3

You can use the cell.CachedValue property to look up cached values.

Francois Botha
  • 4,520
  • 1
  • 34
  • 46