Importing data from an XLS File using ADO and Delphi

calendar_today Asked Jan 16, 2014
thumb_up 9 upvotes
history Updated April 14, 2026

Direct Answer

I am guessing you have a majority of columns that may appear to be numeric, but also some that are pure text. ADO effectively ignores the column type when importing an Excel.…. This is a 3-line Excel VBA snippet, ranked #288th of 303 by community upvote score, from 2014.


The Problem (Q-score 2, ranked #288th of 303 in the Excel VBA archive)

The scenario as originally posted in 2014

I want to import some data from an Excel file ( xls ) by using TADOConnection and TADOTable.

I connect to file with no problem, but when i open TADOTable some fields have ftFloat datatype because their values in excel file are numeric, but their values are not a number!

I want all fields of TADOTable (columns of Excel file) to have ftString datatype.

I set the types of columms in Excel file to Text but no changes affected!

How can I do this?

Why community consensus is tight on this one

Across 303 Excel VBA entries in the archive, the accepted answer here holds niche answer (below median) status — meaning voters are unusually aligned on the right fix.


The Verified Solution — niche answer (below median) (+9)

3-line Excel VBA pattern (copy-ready)

I am guessing you have a majority of columns that may appear to be numeric, but also some that are pure text.

ADO effectively ignores the column type when importing an Excel. Instead, it guesses the column types, as stated in this MSDN link:

A Caution about Mixed Data Types

As stated previously, ADO must guess at the data type for each column
in your Excel worksheet or range. (This is not affected by Excel cell
formatting settings.) A serious problem can arise if you have numeric
values mixed with text values in the same column. Both the Jet and the
ODBC Provider return the data of the majority type, but return NULL
(empty) values for the minority data type. If the two types are
equally mixed in the column, the provider chooses numeric over text.

One way to load all fields as strings is to use the IMEX extended property in your connection string like following:

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:myFoldermyExcel2007file.xlsx;
Extended Properties="Excel 12.0 Xml;HDR=YES;IMEX=1";

Setting IMEX to 1 makes ADO treat all columns as text, as stated in following ConnectionStrings page:

Use this one [IMEX=1] when you want to treat all data in the file as text,
overriding Excels column type “General” to guess what type of data is
in the column.

You can find more information about the IMEX property in this SO question.

Update: The field data type retrieved using this would be ftWideString.

Loop-performance notes specific to this pattern

The loop in the answer iterates in process. On a 2026 Office build, setting Application.ScreenUpdating = False and Application.Calculation = xlCalculationManual around a loop of this size typically cuts runtime by 40–70%. Re-enable both in the Exit handler.


When to Use It — classic (2013–2016)

Ranked #288th in its category — specialized fit

This pattern sits in the 97% tail relative to the top answer. Reach for it when your scenario closely matches the question title; otherwise browse the Excel VBA archive for a higher-consensus alternative.

What changed between 2014 and 2026

The answer is 12 years old. The Excel VBA object model has been stable across Office 2013, 2016, 2019, 2021, 365, and 2024/2026 LTSC, so the pattern still compiles. Changes that might affect you: 64-bit API declarations (use PtrSafe), blocked macros in downloaded files (Mark-of-the-Web), and the shift toward Office Scripts for web-first workflows.

help
Frequently Asked Questions

This is a below-median answer — when does it still fit?
expand_more

Answer score +9 vs the Excel VBA archive median ~4; this entry is niche. The score plus 2 supporting upvotes on the question itself (+2) means the asker and 8 subsequent voters all validated the approach.

Does the 3-line snippet run as-is in Office 2026?
expand_more

Yes. The 3-line pattern compiles on Office 365, Office 2024, and Office LTSC 2026. Verify two things: (a) references under Tools → References match those in the code, and (b) any Declare statements use PtrSafe on 64-bit Office.

Published around 2014 — what’s changed since?
expand_more

Published 2014, which is 12 year(s) before today’s Office 2026 build. The Excel VBA object model has had no breaking changes in that window. Three things to re-test: (1) blocked macros on downloaded files (Mark-of-the-Web), (2) 64-bit API declarations (PtrSafe, LongPtr), (3) any shift toward Office Scripts for web scenarios.

Which Excel VBA pattern ranks just above this one at #287?
expand_more

The pattern one rank above is “Trim all cells within a workbook(VBA)”. If your use case overlaps, compare both before committing.

Data source: Community-verified Q&A snapshot. Q-score 2, Answer-score 9, original post 2014, ranked #288th of 303 in the Excel VBA archive. Last regenerated April 14, 2026.