从 Excel 导入数据[已关闭]

问题描述 投票:0回答:4

如何使用 Delphi 7 将数据从 Excel 导入 Paradox 数据库?

delphi excel delphi-7 paradox
4个回答
6
投票

好吧,如果您有标记为 Delphi 7 的问题,我假设您有 BDE。这将使您能够在 Delphi 中完成整个过程。

您可以修改并使用这个未经测试的代码(您将需要添加异常处理):

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;

5
投票

如何从 Excel 导出 CSV,然后将 CSV 导入 Paradox DB? 您还可以尝试从 Excel 导出 XML,然后以编程方式将 XML 加载到 Padox DB 中。


3
投票

使用Delphi 7中的OLEDB Provider和ADO组件来实现这一点。 做起来应该很简单,你可以通过 SQL 查询来使用 Excel 查询。

使用TADO组件获取数据,然后使用TQuery等BDE组件将数据导入到Paradox表中。


2
投票

这个工具SMImport说它可以做到。虽然他们要 50 美元,但你可以下载免费试用版。

© www.soinside.com 2019 - 2024. All rights reserved.