Topic: Example Auto Import Value Multiple Excel (Easy Code!)

Loop Read Value Multiple Excel File In Folder (MVD Can function for select folder by SelectDirectory(,,,,) )
For MVD Can  modify value to sql insert script to database easy like use time third party database manager import excel function 

Happy ! Happy !
Note ***
Order Cell Table IN MVD start (column(0),row(0))
But
Order Cell Table IN Excel start (row(1),column(1))


https://i.ibb.co/DwV4nHN/2019-03-28-002.png

OpenCode

var
apppath : string;
procedure Form1_Button1_OnClick (Sender: TObject; var Cancel: boolean);
var
i : integer ;
r : integer ;
c : integer ;
ExcelFile : Variant;
WorkBook  : Variant;
WorkSheet : Variant;
MaxRow : Integer;
MaxCol : Integer;
value : String;
sl : Tstringlist ;
sql_code : string;
begin
    sl := Tstringlist.Create ;
    For i:= 0 To Form1.Memo1.lines.count - 1 Do
    Begin
        ExcelFile :=  CreateOleObject('Excel.Application');
        WorkBook  :=  ExcelFile.WorkBooks.Open( Form1.Memo1.Lines[i]) ;
        WorkSheet :=  WorkBook.WorkSheets.Item['sheet1'];
        MaxRow := WorkSheet.Usedrange.EntireRow.count ;
        MaxCol := WorkSheet.Usedrange.EntireColumn.count;
        For r := 2 To MaxRow Do //No Head Column Start At Row 2 Excel
        Begin
            value := '';                       
            For c := 1 To MaxCol Do //Start At Column 1 Excel
            Begin
            value := value +'"'+WorkSheet.Cells[r, c].Value+'",' ;
            End ;
            sql_code := 'Insert OR Ignore Into import_value (long_string) values (''{'+Copy(value,1,Length(value)-1)+'}'');' ;
            Form1.Label1.Caption := sql_code ;
            sl.add(sql_code) ;
        End;
        WorkBook.Save;
        WorkBook.Close;
        ExcelFile.Quit;
    End;
    Application.ProcessMessages;
    Form1.Memo2.Text := sl.text ;
    sl.clear;
    KillTask('EXCEL.EXE');
    Form1.Label1.Caption := IntToStr(Form1.Memo2.Lines.Count)+' Record' ;
    Showmessage( IntToStr(Form1.Memo2.Lines.Count)+' Record');
end;
begin
    apppath := ExtractFilePath(Application.ExeName) ;
    Form1.Memo1.Text := GetFilesList(apppath+'ExcelFile','*.xls*',True);
end.
Post's attachments

Attachment icon LoopReadExcel.zip 363.4 kb, 598 downloads since 2019-03-28 

My Visual Database : I Love You
Easy For Beginner Student For Me

Re: Example Auto Import Value Multiple Excel (Easy Code!)

Thank you

Dmitry.