我需要使用OleDb Connection从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 Cell的值为-0.46256613817052
我的DataSet的值为-0.4625661
Excel表格中的大多数单元格都是数字类型。
如何解决这个问题?请帮忙。
答案 0 :(得分:1)
根据Microsoft.Jet.OLEDB.4.0 rounding excel data?的答案,如果您需要获得准确的值,则需要使用visual studio工具办公。
我使用Excel Data Reader /
解决了这个问题