2

I've been using Closed XML to generate my Excel reports automatically. So far so good, but however I need to save certain formula-generated values back into the database.

The formula would be something like this: =SUM(Day1, Day2, Day3), so simply an Excel formula parser would not fit my bill--I need something that can interact with it!

I don't mind having to save the spreadsheet and then re-opening it. So long as it's fast and efficient, I'm up for anything. Thanks a bunch. :)

matt
  • 2,857
  • 7
  • 33
  • 58

2 Answers2

2

You can use

Range("D1").value 

for getting the value of the formula

Arion
  • 31,011
  • 10
  • 70
  • 88
Sandeep
  • 667
  • 7
  • 25
  • What if, I can only get the cell from a row-col (int, int) reference? – matt Apr 27 '12 at 08:00
  • @matt Have a look [here](http://stackoverflow.com/questions/181596/how-to-convert-a-column-number-eg-127-into-an-excel-column-eg-aa) for a way to convert your integer column number to an Excel column name (remember to account for your possibly-zero based number). – Sid Holland Apr 30 '12 at 05:52
  • 1
    IXLWorksheet's Range().Value does not have a get accessor... says the code – matt May 01 '12 at 15:53
1

You can use something like:

if(ws.Cell(i, j).HasFormula) 
       VAL = ws.Cell(i, j).ValueCached
else
       VAL = ws.Cell(i, j).Value.ToString()
Yahya Hussein
  • 8,767
  • 15
  • 58
  • 114
  • 1
    Code only answers are discouraged on StackOverflow. Please try to elaborate a little as to why this is a correct answer.. – Mittal Patel Feb 13 '18 at 13:44