OLEDB连接不从Excel文件读取所有的行 [英] OleDb Connection not reading all the rows from excel file

查看:294
本文介绍了OLEDB连接不从Excel文件读取所有的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用OleDb在C#连接从Excel表中读取数据。并填入数据表。

I am using an OleDb in C# connection to read data from an Excel sheet. And fill it in a Datatable.

工作表包含275行和27列。我读了之后,第1,2和3行是空的。

The sheet contains 275 rows and 27 columns. After I read it, Rows 1,2 and 3 are empty. All the other rows are filled correctly.

任何人都有这个问题的想法?

Anyone have an idea on the problem?

这里是我的代码:

string connString = "Provider=Microsoft.ACE.OLEDB.12.0;" +
                "Data Source=" + "C:/Sheets/DataSheet.xls" + ";Extended Properties=Excel 12.0;";

objConn = new OleDbConnection(connString);

string Query = "SELECT * FROM [Sheet1$]";
OleDbCommand objCmd = new OleDbCommand(Query, objConn);

DataTable Table = new DataTable();
objAdapter1.SelectCommand = objCmd;
objAdapter1.Fill(Table);


推荐答案

问题是我的工作表包含混合数据只读数字。
解决方案是指定

The problem was that my sheet contained mixed data and it was only reading numbers. The solution is to specify

Properties=\"Excel 12.0;IMEX=1\";"

IMEX = 1允许读者导入所有数据,不仅仅是数字

IMEX=1 allow the reader to import all data not only numbers

这篇关于OLEDB连接不从Excel文件读取所有的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆