델파이를 사용하여 데이터베이스 애플리케이션을 작성하고 Excel 시트에서 데이터를 가져 와서 액세스 데이터베이스에 저장해야합니다. 나는 이것을 어떻게하는지, 어떤 구성 요소를 사용하는지, 심지어 가능할 지 모른다면 나를 도울 수 있습니까?델파이를 사용하여 엑셀 파일을 Access 데이터베이스로 가져 오는 방법
4
A
답변
12
당신은 DoCmd.TransferSpreadsheet
기능을 사용하여)이
1 중 하나를 시도, 몇 가지 옵션이 있습니다,이 방법은 간단하지만 매우 유연하지 않습니다.
{$APPTYPE CONSOLE}
{$R *.res}
uses
SysUtils,
ActiveX,
ComObj;
procedure ImportDataAccess(const AccessDb, TableName, ExcelFileName:String);
Const
acQuitSaveAll = $00000001;
acImport = $00000000;
acSpreadsheetTypeExcel9 = $00000008;
acSpreadsheetTypeExcel12 = $00000009;
var
LAccess : OleVariant;
begin
//create the COM Object
LAccess := CreateOleObject('Access.Application');
//open the access database
LAccess.OpenCurrentDatabase(AccessDb);//if the access database doesn't exist use the NewCurrentDatabase method instead.
//import the data
LAccess.DoCmd.TransferSpreadsheet(acImport, acSpreadsheetTypeExcel9, TableName, ExcelFileName, True);
LAccess.CloseCurrentDatabase;
LAccess.Quit(1);
end;
begin
try
CoInitialize(nil);
try
ImportDataAccess('C:\Data\Database1.accdb','Sales','C:\Data\Sales.xlsx');
Writeln('Done');
finally
CoUninitialize;
end;
except
on E:EOleException do
Writeln(Format('EOleException %s %x', [E.Message,E.ErrorCode]));
on E:Exception do
Writeln(E.Classname, ':', E.Message);
end;
Writeln('Press Enter to exit');
Readln;
end.
2) AD 구성 요소를 사용하면 더 유연한 방법을 사용할 수 있습니다.
{$APPTYPE CONSOLE}
{$R *.res}
uses
Data.DB,
Data.Win.ADODB,
SysUtils,
ActiveX,
ComObj;
procedure ImportDataADO(const AccessDb, TableName, ExcelFileName:String);
var
LAdoQueryExcel : TADOQuery;
LADOAccesCmd : TADOCommand;
begin
LAdoQueryExcel:=TADOQuery.Create(nil);
LADOAccesCmd:=TADOCommand.Create(nil);
try
//set the connection string for access
LADOAccesCmd.ConnectionString:=Format('Provider=Microsoft.ACE.OLEDB.12.0;Data Source=%s;',[AccessDb]);
LADOAccesCmd.Parameters.Clear;
LADOAccesCmd.CommandText:='INSERT INTO Sales (id,name) VALUES (:id,:name)';
LADOAccesCmd.ParamCheck:=False;
//set the connection string for excel
LAdoQueryExcel.ConnectionString:=Format('Provider=Microsoft.ACE.OLEDB.12.0;Data Source=%s;Extended Properties="Excel 12.0 Xml;HDR=YES;IMEX=1"',[ExcelFileName]);
LAdoQueryExcel.SQL.Add('SELECT * FROM [Sheet1$]');
LAdoQueryExcel.Open;
while not LAdoQueryExcel.eof do
begin
LADOAccesCmd.Parameters.ParamByName('id').Value := LAdoQueryExcel.FieldByname('id').AsInteger;
LADOAccesCmd.Parameters.ParamByName('name').Value := LAdoQueryExcel.FieldByname('name').AsString;
LADOAccesCmd.Execute;
LAdoQueryExcel.Next;
end;
finally
LAdoQueryExcel.Free;
LADOAccesCmd.Free;
end;
end;
begin
try
CoInitialize(nil);
try
ImportDataADO('C:\Datos\Database1.accdb','Sales','C:\Datos\Sales.xlsx');
Writeln('Done');
finally
CoUninitialize;
end;
except
on E:EOleException do
Writeln(Format('EOleException %s %x', [E.Message,E.ErrorCode]));
on E:Exception do
Writeln(E.Classname, ':', E.Message);
end;
Writeln('Press Enter to exit');
Readln;
end.
관련 문제
- 1. 엑셀 파일을 h2 데이터베이스로 가져 오는 방법은 무엇입니까?
- 2. 날짜를 가져 오는 동안 데이터를 엑셀 시트에서 데이터베이스로 변환
- 3. 파일을 데이터베이스로 일괄 가져 오는 방법은 무엇입니까?
- 4. 델파이를 사용하여 Access 97 데이터 파일을 열려면 어떻게해야합니까?
- 5. 사용자가 선택한 CSV 파일을 데이터베이스로 가져 오는 방법
- 6. 엑셀 파일에서 데이터를 내보내고 SQL 데이터베이스로 가져 오는 방법은 무엇입니까?
- 7. .NET을 사용하여 CSV 파일을 DB2 데이터베이스로 가져 오는 방법은 무엇입니까?
- 8. Android : xml 형식의 데이터베이스 파일을 sqlite 데이터베이스로 가져 오는 방법?
- 9. 파일을 가져 오는 방법
- 10. 파일을 가져 오는 방법
- 11. 오라클에있는 데이터베이스로 데이터를 가져 오는 방법
- 12. txt 파일을 엑셀로 변환 한 다음 엑셀 수정 및 새 엑셀 파일을 데이터베이스로 가져 오기
- 13. Access 데이터베이스로 Excel 파일을 읽는 가장 좋은 방법
- 14. 엑셀 데이터 매트릭스를 MySQL 데이터베이스로 가져 오기
- 15. 여러 (csv) 파일을 Access db에 가져 오는 방법
- 16. Selenium IDE로 엑셀 값을 가져 오는 방법
- 17. PHP를 사용하여 폼의 checkboxes 배열에서 데이터베이스로 값을 가져 오는 방법
- 18. USB를 사용하여 장치에서 파일을 가져 오는 방법
- 19. 델파이를 사용하여 reg 파일을 가져 오기 (병합) 하시겠습니까?
- 20. Carrierwave로 파일을 가져 오는 방법
- 21. 서버에서 파일을 가져 오는 방법
- 22. 자바를 사용하여 엑셀 파일에서 데이터베이스로 데이터 업로드하기
- 23. CSV 파일에서 MySQL 데이터베이스로 데이터를 가져 오는 방법
- 24. BIG SQL 파일을 레일즈 데이터베이스로 가져 오는 방법은 무엇입니까?
- 25. 큰 wikipedia sql 파일을 mysql 데이터베이스로 가져 오는 방법은 무엇입니까?
- 26. XML 파일을 SQL 서버 데이터베이스로 가져 오기
- 27. vcf 파일을 가져 오는 방법
- 28. nebeans로 파일을 가져 오는 방법
- 29. R.raw에서 파일을 가져 오는 방법
- 30. * .SQL 파일을 가져 오는 방법
더 긴 방법은 COM을 사용하여 CSV를 저장 한 다음 CSV 파일을 구문 분석하고 유효성을 검사하는 것입니다. – ComputerSaysNo