0

I need to get the value (the result of a huge formula) of a worksheet cell, that is being normally displayed when I open the file with Excel.
My code is retrieving correctly the value of 99% of all cells in my worksheets. But not for about 40 of them.

Here is my code:

string fileName = "C:\\Folder1\\template.xlsx";
var workbook = new XLWorkbook(fileName);
var ws = workbook.Worksheet("Formula");
IXLCell cell = ws.Cell("J70");
Console.WriteLine(cell.Value);

Here is the error:

Exception thrown: 'System.NullReferenceException' in ClosedXML.dll
An unhandled exception of type 'System.NullReferenceException' ocurred in ClosedXML.dll
Object reference not set to an instance of an object

After reading the ClosedXML Documentation on github, the only suspicion I have is that my formula is not supported, but the documentation shows the functions in use are. What am I missing?

  • This looks like a bug in ClosedXML. Can you please log an issue on the Github repo. Make sure you complete the full issue template and attach your problematic file. – Francois Botha Oct 31 '18 at 11:03
  • I was doing very silly mistake. I had saved the file by name "template.xlsx". Note the filetype was ".xlsx", so the full filename was "template.xlsx.xlsx". Just save the file with name "template" and make sure it has extension ".xlsx" – Gambitier Jun 18 '20 at 19:00

1 Answers1

0

I got this error once and it was related, as mentioned by you, to a formula not digested well by ClosedXML. For me this has fixed the issue:

Console.WriteLine(ws.Cell("J70")?.GetValue<string>() ?? "No value");
Lapo
  • 31
  • 7
  • 2
    This should be a comment, not an answer. – Zohar Peled Oct 26 '18 at 12:45
  • You have not enough rep to post comments, but this doesn't mean that you can abuse the system and press the Post Your Answer button to ask for clarifications. Please answer the questions where you have enough information to create a valid answer – Steve Oct 26 '18 at 12:46
  • Sorry for this guys and thanks for the highlight. I've changed the aswer :) – Lapo Oct 26 '18 at 12:59
  • that didn't work for me :( but thanks for the help – Jovemsincero Oct 26 '18 at 14:21