Oledb从Excel工作表中读取虚假值

时间:2013-05-13 08:52:17

标签: c# winforms oledb

我正在尝试使用带有以下代码的oledbReader读取窗口浏览器中已经打开的Excel工作表

System.Data.OleDb.OleDbConnection mCon;
mCon.ConnectionString = ("Provider=Microsoft.ACE.OLEDB.12.0;data source=" + openFileDialog1.FileName + ";Extended Properties=\"Excel 12.0;HDR=NO;IMEX=1\";");
strSelectQuery = "SELECT TOP 20 * FROM [$Sheet1]";
        if (mCon.State == ConnectionState.Closed)
        {
            mCon.Open();
        }
        DataAdapter = new System.Data.OleDb.OleDbDataAdapter(strSelectQuery, mCon);
        DataAdapter.Fill(mDTable);
        DataAdapter.Dispose();
        mCon.Close();

这里读取

 03-Aug-12 as 41124 // Excel Column has Genral format
 07:29:19 as 0.31202546296 //Excel Column has Genral format
 359307046362750 as 3.5930704636e+014 // Excel Column has Number Format with Decimal place 0

如果excel文件已关闭,则会以正确的格式读取值。 为什么这样做?

0 个答案:

没有答案