A friend asked how to import Excel into the database, this is my Unigui project code, implement Unidbgrid Import Database function, because with KBMMW, so you see is Unidbgrid import Kbmmwclientquery, Then submit the Clientquery to the database. Share it!
function ImportFromFile (adataset:tkbmmwclientquery; agrid:tunidbgrid; afilename:string): Boolean;
Var
R, c, I:integer;
V:tcellvalue;
Xls:texcelfile;
Begin
Adataset.disablecontrols;
XLS: = Txlsfile.create (False);
Try
Xls. Open (Afilename);
Xls. ActiveSheet: = 1;
for r: = 2to xls. RowCount do
Begin
If not Isblankrow (XLS, R) and then//is not a blank line then fill in
Begin
Adataset.append;
For I: = 0 to Agrid.columns.count-1 do
Begin
c: = Getcolbyname (xls, agrid.columns[i]. Title.caption);
If c <>-1 Then
Begin
Case Adataset.fieldbyname (Agrid.columns[i]. FieldName). Datatypeof
Ftdatetime, Ftdate:
Adataset.fieldbyname (Agrid.columns[i]. FieldName). Asdatetime: =xls. Getcellvalue (R, c). ToDateTime (False);
Else
Adataset.fieldbyname (Agrid.columns[i]. FieldName). Asstring: =xls. Getcellvalue (R, c)
. Tostring.replace (","). Replace (' ' ', ');
End
End
End
Adataset.post;
End
End
Result: =adataset.resolve;
Finally
Adataset.enablecontrols;
Xls. Free;
End
End
Unidbgrid Import Database (turn red fish)