Skip to content

Commit 20281fd

Browse files
authored
Line 419: Null Reference Exception on empty cells
I used the old code ("theCell != null") and got null reference exceptions when cells were empty. I found that theCell.InnerText.Length>0 avoided the null reference exception. Using Object.ReferenceEquals(), or !(x== null) didn't change the outcome.
1 parent 132ca44 commit 20281fd

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

docs/how-to-retrieve-the-values-of-cells-in-a-spreadsheet.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ code sample in C\# and Visual Basic.
416416
Where(c => c.CellReference == addressName).FirstOrDefault();
417417

418418
// If the cell does not exist, return an empty string.
419-
if (theCell != null)
419+
if (theCell.InnerText.Length > 0)
420420
{
421421
value = theCell.InnerText;
422422

0 commit comments

Comments
 (0)