0

I am redoing a project with Delphi 7 and an XLSX file. I connect to the file using ADO. This works fine, and I can get the data just perfectly, and fast.

My problem is that somehow I always get sheet names from ADO in a sorted list.

So, I can have these 3 sheets in my Excel file:

    [MySheet1]  [Blad1]   [Ark1]
       (0)        (1)       (2)    <<< sheet ID number, zero-based

When I connect to Excel, and send the command:

excelcon.GetTableNames(lstSheets.Items,false);

I always get them in sorted order, like this:

Ark1$
Blad1$
Mysheet1$

The listbox I use to display names is of course not with "sorted" property.

Is there any way using ADO to ask for sheet numbers specifically ("what is name of sheet 0").. looping over the sheets.

NOTE Some others have pointed a tip for C++ to order by int ordinalPosition. ("ORDINAL_POSITION"). I am not too sure how to do that in Delphi.

MyICQ
  • 987
  • 1
  • 9
  • 25
  • 1
    Please provide a [mre] – Tom Brunberg Jan 12 '21 at 12:44
  • Why do you need to know the position of sheets? If you view the Excel document as a database, the "position" of a table has no meaning. – Olivier Jan 12 '21 at 12:44
  • @Olivier in principle I do not, except to operators it's confusing to have first sheet listed last. They will have a list of sheets when connecting to choose from. If I did all via software I did not need to care. – MyICQ Jan 12 '21 at 13:19
  • 2
    Then you could use Excel via OLE Automation to retrieve that information. – Olivier Jan 12 '21 at 13:54
  • @TomBrunberg The answer is "it's not possible" (as explained [here](https://stackoverflow.com/questions/1164698/using-excel-oledb-to-get-sheet-names-in-sheet-order)). – Olivier Jan 12 '21 at 15:00
  • 1
    Thanks @Olivier Then the question should be closed as a duplicate. Please cast your vote (as I can't change my close vote anymore (I can just remove), and you have enough reps to cast close votes) – Tom Brunberg Jan 12 '21 at 15:38
  • Can / should I close this myself as a duplicate ? ( I did not mean to break any rules here ) – MyICQ Jan 12 '21 at 15:42
  • @MyICQ I don't know. Voting to close other people's posts require 3000 reps, but perhaps you can close your own posts. Just try it, you won't be able to do anything you are not allowed to (I guess). – Tom Brunberg Jan 12 '21 at 15:48

0 Answers0