日期:2014-05-18  浏览次数:20916 次

C# 读取excel,为什么读不到像12,31.00 CNY这种类型的数据呢?
请教各位:
我用c#开发的windows应用程序,我想读取excel里的内容,但是有个字段是货币格式的,就是读取不到,为什么啊?有什么办法可以取到值呢?
string strconnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+sopath+";Extended Properties=excel 8.0";
conn = new OleDbConnection(strconnection);
conn.Open();
String sql ="select * from [SAPBW_DOWNLOAD$]";
OleDbCommand cmd = new OleDbCommand(sql,conn);
OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
DataSet dataset = new DataSet();
adapter.Fill(dataset);
for (int i=0;i<dataset.Tables[0].Rows.Count-1;i++)
{
.....
dataset.Tables[0].Rows[i][5];
.....
}
dataset.Tables[0].Rows[i][5]==null,为什么呢?

------解决方案--------------------
可能你前面那几行不是货币格式的,建议一列的格式一致
------解决方案--------------------
最好在做EXCEL时所有的单元格都用文本格式