ExcelRowCount:=WorkBook.WorkSheets[1].UsedRange.Rows.Count;
for i := 1 to excelrowcount + 1 do
begin
excelx := excelapp.Cells[i,1].Value;
excely := excelapp.Cells[i,2].Value;
這里呢 是不是也是因為我沒有參考啊?
uj5u.com熱心網友回復:
什么錯誤內容
uj5u.com熱心網友回復:
參考:ComObj
下面是匯入代碼:
var
ASql, APath: String;
ExcelApp: Variant;
AInt: Integer;
begin
with ADOQuery2 do
begin
Close;
sql.Clear;
SQL.Add('select MAX(ordno) as SDREN from ordtelf');
Open;
if FieldByName('SDREN').AsString<>'' then
begin
MessageBox(Self.Handle,'你資料庫有未完成的匯入的資料,請等待之前的資料完成在匯入!','系統提示',mb_iconquestion);
end
else
begin
if messagebox(Self.Handle,'請選擇業務配送資料包!','系統提示',mb_yesno+mb_iconquestion)=idyes then
begin
If OpenDialog1.Execute Then
APath := OpenDialog1.FileName
Else
Exit;
If not FileExists(APath) Then
Begin
messagebox(self.Handle,'你選擇的檔案不存,請核對','提示資訊',mb_iconinformation);
Exit;
End;
Try
Application.ProcessMessages;
ExcelApp := CreateOleObject('Excel.Application');
ExcelApp.Workbooks.Open(APath);
ExcelApp.WorkSheets[1].Activate;
ASql := 'select * from lf where 1=2'; //表名 ,也可以在show里面先打開資料集
ADOQuery1.Close; //資料集的 LockType屬性 要設為 ltBatchOptimistic
ADOQuery1.SQL.Text := ASql; //才可以批量保存
ADOQuery1.Open;
系統可以跑起來 執行匯入訂單功能是就不行
First chance exception at $7581812F. Exception class EOleSysError with message '沒有注冊類, ProgID: "Excel.Application"'. Process Project1.exe (9216)
First chance exception at $7581812F. Exception class EVariantInvalidOpError with message 'Invalid variant operation'. Process Project1.exe (9216)
y:=1;
for x:=1 to dbgrid.FieldCount do
begin
MyExcel.WorkBooks[1].WorkSheets[1].Cells[y,x] := dbgrid.Fields[x-1].DisplayName;
MyExcel.WorkBooks[1].WorkSheets[1].Cells[y,x].Select;
MyExcel.Selection.Font.Bold := true;
MyExcel.WorkBooks[1].WorkSheets[1].Columns[x].ColumnWidth := dbgrid.Fields[x-1].DisplayWidth;
end;
inc(y);
while not dbgrid.DataSource.DataSet.eof do
begin
for x:=1 to dbgrid.FieldCount do
begin
MyExcel.WorkBooks[1].WorkSheets[1].Cells[y,x] := dbgrid.Fields[x-1].AsString;
end;
inc(y);
dbgrid.DataSource.DataSet.next;
end;
end;
眾所周知,C ++的學習曲線陡峭,但是花時間學習這種語言將為您的職業帶來奇跡,并使您與其他開發人員區分開。您會更輕松地學習新語言,形成真正的解決問題的技能,并在編程的基礎上打下堅實的基礎。 C ++將幫助您養成良好的編程習慣(即清晰一致的編碼風格,在撰寫代碼時注釋代碼,并限制類內部的可見性),并且由 ......
值傳遞不會改變本身,參考傳遞(如果傳遞的值需要實體化到堆里)如果發生修改了會改變本身。 1.基本資料型別都是值傳遞 package com.example.basic; public class Test { public static void main(String[] args) { int ......