无法将null转换为“bool”,因为它是不可为空的值types

我正在创buildfor循环来检查单元格是否为excel表单为空,我得到的错误消息是

“未知模块”中出现未处理的“Microsoft.CSharp.RuntimeBinder.RuntimeBinderException”types的exception。 附加信息:不能将null转换为'bool',因为它是一个不可为空的值types。

我尝试转换为另一个线程中build议的string,但我很不幸。

我正在使用Microsoft Excel 12.0对象库。

这是我的代码:

for (int i = 1; i < 55555; i++) { if (xlWorkSheet.Cells[i, 1] = null) { //////Write data into the cell } else { //// i++; } } 

它应该是xlWorkSheet.Cells[i, 1] == null = single =将值赋给单元格。

  if (xlWorkSheet.Cells[i, 1] = null) { //////Write data into the cell } else { //// i++; } 

不是

  xlWorkSheet.Cells[i, 1] = null 

它应该是

  xlWorkSheet.Cells[i, 1] == null 

=是赋值运算符,而==用于比较。