简体   繁体   中英

Delphi - Excel rows get by an ADO Query

I have the following excel file

在此处输入图片说明

I set AdoConnection.ConnectionString to

 AdoConnection.ConnectionString :=' Provider=Microsoft.Jet.OLEDB.4.0;' +
           'Data Source=' +aFileName + ';' +
           'Extended Properties=Excel 8.0;';

where aFileName is the excel file name.

After that, with an ADOQuery component(connection set to AdoConnection) I perform a 'select * from [Sheet1$]'.

The problem is that rows 16802 and 17179 are not present in the query result,and I don't know why. All the fields from the sheet are set to general. I'm using Delphi 7.

Do you have any ideas?

LE:type of all the fields from the AdoQuery are WideString. In query are present only the rows where values from the last 2 columns have that 'green sign'. I'm not a genius in Excel, but the query should not get all the data existing in a sheet?

By default it examines the first couple rows and uses that to determine the column type. When the type it chooses is text all numeric values in that column will come across as null.

The solution is to use import mode (IMEX=1). Note that this has odd behvaiour if your also trying to update rows.

 AdoConnection.ConnectionString :=' Provider=Microsoft.Jet.OLEDB.4.0;' +
       'Data Source=' +aFileName + ';' +
       'Extended Properties="Excel 8.0;IMEX=1"';

PRB: Excel Values Returned as NULL Using DAO OpenRecordset

The one thing that comes to mind is that among the hidden rows there are one or more rows that have no value in any cell. Excel usually takes the first entirely empty row and column to be the bounds of a data range. Data range in this case is not "just and ol'" data range but a set of rows and columns that Excel treats as a table. Which is what you do by accessing the sheet through Ado.

第2行在D行和D行中都有一些数字字段,您应该将此值更改为string,可以将单元格的类型更改为text。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM