文字列リストに項目を追加しています。挿入するデータが存在することはわかっていますが、null 参照エラー メッセージが表示され続けます。Object reference not set to an instance of an object.
public class ExcelRow
{
public List<String> lstCells;
public byte[] rowHash;
......
}
public class ExcelInfo
{
public List<ExcelRow> excelRows;
}
public ExcelInfo ReadExcel(OpenFileDialog openFileDialog)
{
var _excelFile = new ExcelQueryFactory(openFileDialog.FileName);
var _info = from c in _excelFile.WorksheetNoHeader() select c;
ExcelRow excelRow;
ExcelInfo resp;
resp = new ExcelInfo();
foreach (var item in _info)
{
excelRow = new ExcelRow();
excelRow.lstCells.Add(item.ElementAt(0));
excelRow.lstCells.Add(item.ElementAt(1));
excelRow.lstCells.Add(item.ElementAt(2));
excelRow.lstCells.Add(item.ElementAt(3));
.....
excelRow.CalculateHash();
resp.excelRows.Add(excelRow);
}
return resp;
}
これは私がエラーを取得している場所です:excelRow.lstCells.Add(item.ElementAt(0));