3

I want to import data from Excel into a Paradox database on Delphi 7.

How can I do that using Delphi?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user578332
  • 325
  • 1
  • 5
  • 16
  • 4
    There's no question here. This is a statement. Sorry, but I am compelled to vote to close. – David Heffernan Feb 20 '11 at 19:48
  • 2
    No need for Delphi. Make sure you have the Paradox ODBC drivers installed, then connect to them from within Excel. Works like a charm; see [here][1] for more info on the various kinds of ODBC drivers you can use. --jeroen [1]: http://www.dbforums.com/corel-paradox/1218996-connecting-paradox-tables-access-other-sql-client.html – Jeroen Wiert Pluimers Feb 20 '11 at 22:03
  • 2
    +1; vote for re-open. Even with the question phrased as a statement, I think it is clear what the OP wants. – Jeroen Wiert Pluimers Feb 20 '11 at 22:05
  • 1
    +1 vote for reopening. C'mon, the question is obvious, so I added it. Shall we help new users out? – Gregor Brandt Feb 20 '11 at 22:32
  • @gbrandt - When the poster doesn't go into the trouble of properly describing the problem or even asking it, there's a good chance that you won't be addressing the actual problem, or you won't be addressing the problem in a way that the poster desires. If the appendage you made to the question would have indeed been the actual question, the poster would have got his answer with his first attempt (http://stackoverflow.com/questions/4957414/how-connect-excel-2007-for-delphi7). – Sertac Akyuz Feb 20 '11 at 22:35
  • The poster had ample opportunity to clarify the question. – David Heffernan Feb 20 '11 at 22:41
  • 1
    Not everyone uses english as a first language. – Gregor Brandt Feb 20 '11 at 22:42
  • 2
    @gbrandt that doesn't matter, the poster didn't attempt to edit the question to make it clear. This is a user with 8 existing questions. We are not talking about a new user. – David Heffernan Feb 20 '11 at 22:45
  • @David - so how many questions make a "new user"? I still wish I can retract my reopen vote since a ♦mod has spoken – RichardTheKiwi Feb 20 '11 at 22:50
  • @Richard well, you've only been here 40 days, but I'm not sure I'd class you as new with all that rep! – David Heffernan Feb 20 '11 at 22:52
  • 1
    At least one would expect some feedback. There's an answer to the previous attempt and two answers and some comments to this one... – Sertac Akyuz Feb 20 '11 at 22:52

4 Answers4

6

Well, if you have the question tagged as Delphi 7 I assume you have BDE. This will enable you to do the whole process in Delphi.

You can modify and use this untested code (you will need to add the exception handling):

procedure TForm1.Button2Click(Sender: TObject);
var
  Cols: integer;
  Rows: integer;
  IntCellValue: integer;
  Excel, XLSheet: Variant;
  failure: Integer;

begin
  failure:=0;
  try
    Excel:=CreateOleObject('Excel.Application');
  except
    failure:=1;
  end;
  if failure = 0 then
  begin
    Excel.Visible:=False;
    Excel.WorkBooks.Open(<Excell_Filename>);
    XLSheet := Excel.Worksheets[1];
    Cols := XLSheet.UsedRange.Columns.Count;
    Rows := XLSheet.UsedRange.Rows.Count;

    // Value of the 1st Cell
    IntCellValue:=Excel.Cells[1, 1].Value;
    // Iterate Cals/Rows to read the data section in your worksheet
    // and you can write it in Paradox using the BDE by iterating all cells
    // somthing like this pseudo code:

      try            
        Query := TQuery.Create(nil)            
        Query .Databasename := PdxDBName; // must be configured in the BDE
        while Rows > 0
        begin
          while Cols > 0
          begin
            IntCellValue:=Excel.Cells[Cols,Rows].Value;
            Query .SQL.text := // SQLStmt including the IntCellValue
            ExecSQL;
            dec(Cols);               
          end;
          Cols := XLSheet.UsedRange.Columns.Count;
        Dec(Rows);
        end;
      finally
        Query.Free;
      end;

    Excel.Workbooks.Close;
    Excel.Quit;
    Excel:=Unassigned;
  end;
end;
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
CloudyMarble
  • 36,908
  • 70
  • 97
  • 130
  • I tried that reading an xlsx file. At the line XLSheet := Excel.Worksheets[1] it throws an exception with the message "OLE error 800A03EC". Any ideas why that is happening? – Mark Patterson Nov 14 '16 at 01:18
5

What about CSV from Excel then import the CSV into Paradox DB? You may also try exporting XML from Excel, then load the XML into Padadox DB programmatically.

mozillanerd
  • 568
  • 4
  • 9
3

Use the OLEDB Provider and ADO component in Delphi 7 to achieve this. It should be simple to do, and you can work with Excel querying via SQL queries.

Use the TADO component to get the data and then use BDE components like TQuery to import the data to the Paradox table.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Senthil Kumar B
  • 926
  • 6
  • 13
  • 1
    Please don't add 'taglines' to your answers, there's a place on your profile (which you have discovered) to put your URL if people are interested. – Tim Post Feb 21 '11 at 16:27
2

This tool SMImport says it can do it. While they want $50 for it, you can download a free trial version.

DOK
  • 32,337
  • 7
  • 60
  • 92