我正在尝试将 Excel 工作表数据读取到数据表以绑定到 GridView。我的 Excel 表包含如下数据,
ID Value1 Value2
-------------------------------------------------
1 $312976.97530297 $30790.0614862584
etc
我正在使用以下代码将值读取到数据表中。
DataTable table = new DataTable();
string filePath = @"D:\Book1.xlsx";
string strConn = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1;TypeGuessRows=0;ImportMixedTypes=Text\"", filePath);
using (OleDbConnection dbConnection = new OleDbConnection(strConn))
{
using (OleDbDataAdapter dbAdapter = new OleDbDataAdapter("SELECT ID, value1,value2 FROM [Sheet1$]", dbConnection))
dbAdapter.Fill(table);
}
问题:由于 value1 和 value2 包含 $ 符号,dataAdaptor 检索两个值都没有完全精度,即。而不是 312976.97530297,它只返回 312976.9753。
Note:
1. I cannot change the input Excel sheet since the enduser will upload it to the web site.
2. If i remove the $ symbol in the excel sheet, it will return the full precision, but $ also present in the input sheet.
3. I tried using Microsoft.Office.Interop.Excel and its working, but the performance is very low.
Or I can format all the excel cell as Text/General type before filling to the datatable, Anyone knows how to do that?
请建议一种使用 OleDbDataAdapter 的方法。
在此先感谢,威尔逊。