c# - 从 Excel 读取值时丢失精度

标签 c# excel oledb

我需要使用 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/

相关文章:

c# - 什么是标准的 Akka.Net 消息命令验证模式?

c# - 比较接口(interface)的 GenericTypeDefinition

c# - 以编程方式将新用户插入到 aspnet 成员资格架构中

c# - 如何知道枚举器是否已到达 C# 中集合的末尾?

c# - Windows 7 上的 Microsoft.jet.oledb.4.0 错误

ms-access - VBScript 和 Access MDB - 800A0E7A - "Provider cannot be found. It may not be properly installed"

node.js - 用于写入 excel 文件的 Node XLSX

excel - 使用Excel "IF"语句过滤掉以某个字符开头或结尾的文本

excel - 从 VBA Excel 打开和关闭 Word 文档

c# - C# winform中的excel列选择查询