Delphi - 通过ADO查询获取Excel行 [英] Delphi - Excel rows get by an ADO Query

查看:207
本文介绍了Delphi - 通过ADO查询获取Excel行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下excel文件

I have the following excel file

我将AdoConnection.ConnectionString设置为

I set AdoConnection.ConnectionString to

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

其中aFileName是excel文件名。

where aFileName is the excel file name.

之后,使用ADOQuery组件(连接设置为AdoConnection),我从[Sheet1 $]中执行'select *'。

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

问题是行16802和17179不存在于查询结果中,我不知道为什么。表格中的所有字段都设置为一般。我正在使用Delphi 7。

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.

你有什么想法吗?

LE:AdoQuery中所有字段的类型都是WideString。在查询中只显示最后2列的值为绿色符号的行。我不是Excel中的天才,但查询不应该得到表中的所有数据?

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.

解决方案是使用导入模式(IMEX = 1)。请注意,如果您还尝试更新行,则这个行为是奇怪的。

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:使用DAO OpenRecordset返回为NULL的Excel值

这篇关于Delphi - 通过ADO查询获取Excel行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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