Home > Back-end >  Consult the import EXCEL how to realize the number listed in the table number is will the bank into
Consult the import EXCEL how to realize the number listed in the table number is will the bank into

Time:09-28


Such as EXCEL spreadsheet

The project name drawing no. Product name specifications unit quantity
Safety management engineering CP station free water dehydrator art 476-2013 4000 * 22000 4
Injection allocation station system test station construction project - 42892 free water dehydrator separation buffer Φ 4000 2
.
.
.

Implements the following effect
Is through the import button to import the first line of information in four DBGRIDEH1, import twice, the second line of information and so on,

The project name drawing no. Product name specifications unit quantity
Safety management engineering CP station free water dehydrator art 476-2013 4000 * 22000 4
Safety management engineering CP station free water dehydrator art 476-2013 4000 * 22000 4
Safety management engineering CP station free water dehydrator art 476-2013 4000 * 22000 4
Safety management engineering CP station free water dehydrator art 476-2013 4000 * 22000 4
Injection allocation station system test station construction project - 42892 free water dehydrator separation buffer Φ 4000 2
Injection allocation station system test station construction project - 42892 free water dehydrator separation buffer Φ 4000 2


The following is my every information only import a code
Procedure TForm1. Button28Click (Sender: TObject);
Var I: integer;
ColumnNO: string;
MsExcel msExcelWorkBook, msExcelWorkSheet: variant;

The begin
Try
OpenDialog1. FileName:='*. XLS';
If not OpenDialog1. Execute then
The begin
Exit;
The end;
If ExtractFileExt (OpenDialog1 FileName) & lt;> 'like' then
The begin
MessageBox (0, 'please choose the right Excel file, PChar (' tip'), MB_OK or MB_ICONWARNING);
Exit;
The end;
MsExcel:=CreateOleObject (' Excel. Application);
MsExcel. Visible:=true;
MsExcelWorkBook:=MsExcel. WorkBooks. Open (OpenDialog1. FileName);
Except,
Exit;
The end;

MsExcelWorkSheet:=msExcel. WorkSheets. Item [1].
Table2. Open;
For I:=2 to msExcelWorkSheet. Rows. Count the do
The Begin
ColumnNO:=msExcelWorkSheet. Range [CRH (65) + IntToStr (I)]. The Value;
If ColumnNO<> "' then
The Begin
Table2. Append;
Table2. FieldByName (' unit using) AsString:=ColumnNO;
Table2. FieldByName (' project name) AsString:=msExcelWorkSheet. Range [CRH (66) + IntToStr (I)]. The Value;
Table2. FieldByName (' # '). The AsString:=msExcelWorkSheet. Range [CRH (67) + IntToStr (I)]. The Value;
Table2. FieldByName (" product name "). The AsString:=msExcelWorkSheet. Range [CRH (68) + IntToStr (I)]. The Value;
Table2. FieldByName (" specifications "). The AsString:=msExcelWorkSheet. Range [CRH (69) + IntToStr (I)]. The Value;
Table2. FieldByName (' units'). AsString:=msExcelWorkSheet. Range [CRH (70) + IntToStr (I)]. The Value;
Table2. FieldByName (' number '). AsString:=msExcelWorkSheet. Range [CRH (71) + IntToStr (I)]. The Value;
Table2. FieldByName (' delivery date). AsFloat:=msExcelWorkSheet. Range [CRH (72) + IntToStr (I)]. The Value;
Table2. FieldByName (' plan to upload date). AsString:=msExcelWorkSheet. Range [CRH (73) + IntToStr (I)]. The Value;

Table2. Post;
End the else
Break;
The End;
Table2. Close;
MsExcel. Quit;

Table2. Close;
Table2. Open;
Table2. Last;
The end;

CodePudding user response:

General ways:
1, open the Excel, starting from the second line line read,
2, after reading a line, to determine the number, how much is saved to a variable (sl),
3, add a for loop, from 1 to sl,
4, in the for loop, insert the current line to the table,
  • Related