ExcelからDelphi7のParadoxデータベースにデータをインポートしたいと思います。
Delphiを使用してそれを行うにはどうすればよいですか?
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;
ExcelからCSVを取得してから、CSVをParadox DBにインポートするのはどうですか?また、ExcelからXMLをエクスポートしてから、プログラムでXMLをPadadoxDBにロードすることもできます。
これを実現するには、Delphi7のOLEDBプロバイダーとADOコンポーネントを使用します。実行は簡単で、SQLクエリを介してExcelクエリを操作できます。
TADOコンポーネントを使用してデータを取得してから、 TQueryなどのBDEコンポーネントを使用してデータをParadoxテーブルにインポートします。
このツールSMImportはそれができると言っています。彼らはそれのために50ドルを望んでいますが、あなたは無料の試用版をダウンロードすることができます。