It is working fine for me to read excel 2007 using LinQ and openXML:
IEnumerable<String> textValues =
from cell in row.Descendants<Cell>()
where cell.CellValue != null
select
(cell.DataType != null
&& cell.DataType.HasValue
&& cell.DataType == CellValues.SharedString
? sharedStrings.ChildElements[
int.Parse(cell.CellValue.InnerText)].InnerText
: cell.CellValue.InnerText)
;
However, if one of my cells are null (blank). Then they are excluded in the textValues. How can I change the query in order to select all cells included blank values, I already tried this query:
from cell in row.Descendants<Cell>()
select cell.CellValue.ToString();
but I got this error:
Object reference not set to an instance of an object.
How should the select query to be?
Thanks in advance.
Try:
cell.CellValueisnulland you get the exception when callingToString()on it.