Topic: Example Import Excel into Table (Script Easy ! )
Reference From
Get data from excel file
http://delphiexamples.com/others/excelinfo.html
&
Fast way to load Excel spreadsheet [closed]
https://stackoverflow.com/questions/148 … preadsheet
Try Edit Code Fun & Easy For MVD Community
OpenCode
procedure Form1_Button3_OnClick (Sender: TObject; var Cancel: boolean);
var
i_sql : integer ;
begin
For i_sql := 0 To Strtoint(Form1.Label1.Caption) -1 Do
Begin
SQLExecute(Form1.Memo1.Lines[i_sql]) ;
Form1.Label2.Caption := IntToStr(i_sql+1) ;
Form1.Label3.Caption := FormatFloat('0.00',(i_sql+1)/StrTOInt((Form1.Label1.Caption))*100)+' %' ;
Application.ProcessMessages;
End;
Application.ProcessMessages;
Form1.TableGrid1.dbUpdate ;
end;
procedure Form1_Button2_OnClick (Sender: TObject; var Cancel: boolean);
var
Excel : Variant ;
Sheet : Variant ;
rows, columns : Integer;
MaxRow : Integer;
MaxCol : Integer;
result_string : string;
sql_string : string ;
irows : integer ;
begin
Excel:=CreateOleObject('Excel.Application');
//Excel.Visible:= True;
Excel.Workbooks.Open(Form1.Edit1.Text) ;
Sheet := Excel.WorkSheets[1] ;
MaxRow := Sheet.Usedrange.EntireRow.count ;
MaxCol := sheet.Usedrange.EntireColumn.count;
//special excel[row,column]
irows := 0 ;
For rows := 2 To MaxRow Do
Begin
For columns := 1 To Maxcol Do
Begin
result_string := result_string + '"'+Excel.ActiveSheet.Cells[rows,columns].Value+'",'
End;
sql_string :=
'INSERT OR IGNORE INTO import_excel(id,date_text,year_text,month_text,day_text) values ('+
copy(result_string,1, Length(result_string)-1)+');';
Form1.Memo1.Lines.Add(sql_string) ;
irows := irows +1 ;
result_string := '' ;
sql_string := '' ;
Form1.Label1.Caption := IntToStr(irows);
End;
Application.ProcessMessages;
Excel.Workbooks.Close;
KillTask('EXCEL.EXE');
end;
procedure Form1_Button1_OnClick (Sender: TObject; var Cancel: boolean);
var
opendialog : Topendialog ;
begin
opendialog := Topendialog.Create(Form1) ;
IF opendialog.execute Then
Form1.Edit1.Text := opendialog.filename ;
opendialog.free;
end;
begin
end.
Easy For Beginner Student For Me