22-12-2020, 01:35 PM
22-12-2020, 07:59 PM
وعليكم السلام ورحمة الله
الطرق مختلفة ممكن الاتصال بملف اكسل عبر مكونات Ado بكلاتا قاعدتي البيانات وبعدها ومن خلال Loop نقل البيانات
او باستخدام طريقة مباشرة من هذا الملف الى الملف الاخر عن
اولا عن طريق الدالة [size=small] [/size][/url]
[url=http://msdn.microsoft.com/en-us/library/bb214134%28office.12%29.aspx]
مثال
والمثال الثاني عن طريق ado components
الطرق مختلفة ممكن الاتصال بملف اكسل عبر مكونات Ado بكلاتا قاعدتي البيانات وبعدها ومن خلال Loop نقل البيانات
او باستخدام طريقة مباشرة من هذا الملف الى الملف الاخر عن
اولا عن طريق الدالة [size=small] [/size][/url]
كود :
DoCmd.TransferSpreadsheetمثال
كود :
{$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.والمثال الثاني عن طريق ado components
كود :
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.23-12-2020, 09:06 AM
كيف أنقل الجداول من excel الى قاعدة paradox ؟
http://delphi4arab.net/forum/showthread.php?tid=269
دلفي و الأكسل
http://delphi4arab.net/forum/showthread.php?tid=3299
Excel من دلفي عبر ADO
http://delphi4arab.net/forum/showthread.php?tid=2851
مشكلة في تحويل ملف excel الى قاعدة بيانات Paradox
http://delphi4arab.net/forum/showthread.php?tid=1860
كيف يتم نقل محتويات خلايا معينة من اكسل الى اكسس عن طريق ado
http://delphi4arab.net/forum/showthread.php?tid=2368
http://delphi4arab.net/forum/showthread.php?tid=269
دلفي و الأكسل
http://delphi4arab.net/forum/showthread.php?tid=3299
Excel من دلفي عبر ADO
http://delphi4arab.net/forum/showthread.php?tid=2851
مشكلة في تحويل ملف excel الى قاعدة بيانات Paradox
http://delphi4arab.net/forum/showthread.php?tid=1860
كيف يتم نقل محتويات خلايا معينة من اكسل الى اكسس عن طريق ado
http://delphi4arab.net/forum/showthread.php?tid=2368