我需要使用 OleDb 连接将值从 Excel 读取到 DataSet。 下面是我的代码。
OleDbCommand excelCommand = new OleDbCommand();
OleDbDataAdapter excelDataAdapter = new OleDbDataAdapter();
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=" + filelocation + @";Extended Properties=""Excel 8.0; IMEX=1;HDR=NO;""";
OleDbConnection excelConn = new OleDbConnection(connectionString);
excelConn.Open();
excelCommand = new OleDbCommand("SELECT * FROM [Sheet1$]", excelConn);
excelDataAdapter.SelectCommand = excelCommand;
excelDataAdapter.Fill(ds);
在阅读时,我的细胞正在失去精度。
例如: Excel 单元格的值为 -0.46256613817052
我的数据集的值为 -0.4625661
我在 Excel 工作表中的大部分单元格都是数字类型。
如何解决?请帮忙。
最佳答案
根据这个答案 Microsoft.Jet.OLEDB.4.0 rounding excel data? ,如果需要获取精确值,需要使用visual studio tools for office。
我已经使用 Excel Data Reader 解决了这个问题/
关于c# - 从 Excel 读取值时丢失精度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28061215/