0

我正在尝试使用 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 文件已关闭,它会以正确的格式读取值。为什么要这样做?

4

0 回答 0