As title, I see baidu garage with related code, but many in the paste to delpi are wrong for example
ExcelApp, WorkBook: Olevariant;
ExcelApp:=CreateOleObject (' Excel. Application);
Creatoleobject is red wavy lines, here, the display is wrong
Have superior to I can realize the function of the complete code for ah ~ ~ ~ ~ ~ ~
CodePudding user response:
CreateOleObject place error, because there is no reference ComObj unit
CodePudding user response:
reference 1st floor twtynk1 response: CreateOleObject error, because there is no reference ComObj unit Ok ~ ~ THX ~ ~ ExcelApp, WorkBook: Olevariant; ExcelRowCount:=WorkBook. WorkSheets [1]. UsedRange. Rows. Count ; For I:=1 to + 1 do excelrowcount The begin Excelx:=excelapp Cells [I, 1]. Value ; Excely:=excelapp Cells [I, 2]. Value ; Are here is because I don't have a reference? CodePudding user response:
Anything wrong CodePudding user response:
refer to the second floor u011609265 response: Quote: refer to 1st floor twtynk1 response: CreateOleObject place error, because there is no reference ComObj unit Ok ~ ~ THX ~ ~ ExcelApp, WorkBook: Olevariant; ExcelRowCount:=WorkBook. WorkSheets [1]. UsedRange. Rows. Count ; For I:=1 to + 1 do excelrowcount The begin Excelx:=excelapp Cells [I, 1]. Value ; Excely:=excelapp Cells [I, 2]. Value ; Are here is because I don't have a reference? Reference: ComObj Here is the import code: var ASql APath: String; ExcelApp: Variant; AInt: Integer; The begin With ADOQuery2 do The begin The Close; SQL. The Clear; SQL. The Add (' select MAX (ordno) as SDREN from ordtelf '); The Open; If FieldByName (' SDREN). AsString<> "' then The begin MessageBox (Self. Handle, 'you have unfinished import data database, please wait until the data to complete the import! 'and' system ', mb_iconquestion); End The else The begin If messagebox (Self. Handle, 'please select a business distribution packet! ', 'prompt', mb_yesno + mb_iconquestion)=idyes then The begin If OpenDialog1. Execute Then APath:=OpenDialog1 FileName The Else The Exit; If not FileExists (APath) Then The Begin Messagebox (self. Handle, 'the file does not save you choose, please check it', 'message' mb_iconinformation); The Exit; The End; Try Application. ProcessMessages; ExcelApp:=CreateOleObject (' Excel. Application); ExcelApp. Workbooks. Open (APath); ExcelApp. WorkSheets [1]. Activate; ASql:='select * from lf the where 1=2'.//the name of the table, also can be in the show opens first data set ADOQuery1. Close;//LockType attribute of a data set to set as ltBatchOptimistic ADOQuery1. SQL. Text:=ASql;//to batch save ADOQuery1. Open; For AInt:=2 To ExcelApp. ActiveSheet. UsedRange. Rows. Count the Do//AInt starting line number, the heavy line which began To import, AInt initial value is a few The Begin ADOQuery1. Append; ADOQuery1. FieldByName (' ordno). AsString:=ExcelApp. Cells [AInt, 1]. The Value; What is the row,//Aint behind the Numbers is which columns, ADOQuery1. FieldByName (' ordtype). AsString:=ExcelApp. Cells [AInt, 2]. The Value; ADOQuery1. FieldByName (' ordbdate). AsDateTime:=ExcelApp. Cells [AInt, 3]. The Value; ADOQuery1. FieldByName (' ordedate). AsDateTime:=ExcelApp. Cells [AInt, 4]. The Value; ADOQuery1. FieldByName (' ordsd). AsString:=ExcelApp. Cells [AInt, 5]. The Value; ADOQuery1. FieldByName (' ordmd). AsString:=ExcelApp. Cells [AInt, 6]. The Value; ADOQuery1. FieldByName (' ordcity). AsString:=ExcelApp. Cells [AInt, 7]. The Value; ADOQuery1. FieldByName (' ordcon). AsString:=ExcelApp. Cells [AInt, 8]. The Value; ADOQuery1. FieldByName (' ordadd). AsString:=ExcelApp. Cells [AInt, 9]. Value; ADOQuery1. FieldByName (' ordtel). AsString:=ExcelApp. Cells [AInt, 10]. Value; ADOQuery1. FieldByName (' ordmey). AsString:=ExcelApp. Cells [AInt, 11]. Value; ADOQuery1. FieldByName (' ordsku). AsString:=ExcelApp. Cells [AInt, 12]. Value; ADOQuery1. FieldByName (' ordskuname). AsString:=ExcelApp. Cells [AInt, 13]. Value; ADOQuery1. FieldByName (' ordqty). AsFloat:=ExcelApp. Cells [AInt, 14]. Value; ADOQuery1. FieldByName (' ordte). AsString:=ExcelApp. Cells [AInt, 15]. Value; ADOQuery1. Post; The End; The Finally ExcelApp. WorkBooks. Close; ExcelApp. Quit; The End; end; end; end; CodePudding user response:
Post your anomaly information, and anomaly breakpoints in the code that, CodePudding user response:
CodePudding user response:
This contact, for the first time, the above is my copy from the Internet to the modified code where it is wrong,, CodePudding user response:
Can you compile? CodePudding user response:
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull