Home > Back-end >  Excel import SQL tool source
Excel import SQL tool source

Time:12-08

Excel import SQL tools source,

Some work is a form of at ordinary times, trouble to do it, or in the database, convenient operation,,
Points is not enough to add

CodePudding user response:

This is the basic operation of the database:
1, open reading EXCEL table in XLSReadWriteII4 controls, and data read, read in the lines, Cell,
2, will read in an array,
2, array through the SQL statements written (insert DBGrid) specified in the table,

Code about so, prompt:
 
For Row:=6 to XLS. Sheets [0]. Do LastRow - 1
The begin
First:=Row;
If (XLS. Sheets [0]. AsString [0, First] <> ") and (XLS. Sheets [0]. AsString [1, First] <> ") and
(XLS. Sheets [0]. AsString [1, First] <> ") and (XLS. Sheets [0]. AsString [17, First]='0') then//ticket is
The begin
If the First=(XLS. Sheets [0]. LastRow - 1)
Then the begin
The Last:=First;
End
The else begin
If (XLS. Sheets [0]. AsString [0, + 1] First & lt;> ") and (XLS. Sheets [0]. AsString [1, + 1] First & lt;> ") and
(XLS. Sheets [0]. AsString [1, + 1] First & lt;> ") and (XLS. Sheets [0]. AsString [17, First + 1]='0')
Then the begin
The Last:=First;
End
The else begin
The Last:=First;
Repeat
The Last: Last +=1;
Until (XLS. Sheets [0]. AsString [9, Last]='subtotal') or (Last>=XLS. Sheets [0]. LastRow - 1);
end;
end;
A: [Top, 0]=XLS. Sheets [0]. AsString [6, First];
A: [Top, 1]=XLS. Sheets [0]. AsString [0, First];
A: [Top, 2]=XLS. Sheets [0]. AsString [1, First];
A: [Top, 3]=XLS. Sheets [0]. AsString [2, the First];
A: [Top, 4]=XLS. Sheets [0]. AsString [9, Last];//subtotal
.
Top:=Top + 1;
end;
end;
XLS. Free;
DateTimetoString (ID1, 'yyyyMMddnnss, Now);
For I:=0 to do Top - 1
The begin
ID=ID1 + IntToStr (100 + I);
With DBGridEh1. The DataSource. The DataSet do
The begin
Append.
J:=Pos (' ', A [I, 0]).
S:=Copy (A [] I, 0, 1, J - 1);
DDate:=StrToDate (S);
FieldByName (" date "). AsString:=FormatdateTime (' - dd yyyy - MM, dDate);
FieldByName (' invoice code). AsString:=A (I, 1);
FieldByName (' invoice number). AsString:=A [I, 2);
FieldByName (' the name of the drawee). AsString:=A (I, 3),
The else FieldByName (' way of income). AsString:='cash';
FieldByName (' drawer). AsString:=A, [I, 30].
FieldByName (' 1 'project). AsString:=A (I, 6),
FieldByName (' 1 'amount.) asString:=A, [7] I,.
FieldByName (' project 2 '). AsString:=A (I, 8),
FieldByName (amount of '2'). AsString:=A, [I, 9].
FieldByName (' ID '.) asString:=ID;
Post;
end;
end;


CodePudding user response:

With AdoDataSet controls, you can open the excel file, the next operation is the operation of the record set,
Connection string is:
The Provider=Microsoft. Jet. The OLEDB. 4.0; The Data Source=d: \ test. XLS; Extended Properties="Excel 8.0; HDR=YES; IMEX=1 "; Persist Security Info=False

CodePudding user response:

If the database is SQL server, then handle the excel format, use SSMS to guide directly,
  • Related