在Excel文件

时间:2015-06-16 16:42:20

标签: c# excel

我想计算Excel表格中空单元格的数量。

我读取了所有Excel工作表的双精度值但我无法计算空值,因为下面的代码可能不起作用。

string path_connection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + testbox_bath.Text + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES\"";

OleDbConnection connection = new OleDbConnection(path_connection);

OleDbDataAdapter adapter_STDsamverkan = new OleDbDataAdapter("Select [Kvalitetsklass (null)],[Std samverkan (null)]" + "from [Sheet1$]", connection);

DataTable dt_STDsamverkan = new DataTable();

adapter_STDsamverkan.Fill(dt_STDsamverkan);

for (int i = 0; i < dt_STDsamverkan.Rows.Count; i++)
{    
   if (dt_STDsamverkan.Rows[i].Field<double>(1) == null)
   {
        STDsamverkan_count2++;
   }
}

IF语句的提示是

  

表达式的结果总是为'false',因为类型的值   'double'永远不会等于'double'类型的'null'

我该怎么办?

1 个答案:

答案 0 :(得分:0)

我在阅读Datatable时使用Double。双重可以为空。

以下链接提供此问题的答案:

double and null in c#