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;
这里呢 是不是也是因为我没有引用啊?
#3
什么错误内容
#4
引用: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;
#12
这台电脑有装Excel吗
#13
这台电脑有装Excel吗
有哇。。
#14
这台电脑有装Excel吗
有哇。。
你确定装的是微软的excel?不是WPS?
#1
CreateOleObject处报错,是因为没有引用ComObj单元
#2
CreateOleObject处报错,是因为没有引用ComObj单元
可以了~~thx~~
ExcelApp,WorkBook:Olevariant;
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;
这里呢 是不是也是因为我没有引用啊?
#3
什么错误内容
#4
CreateOleObject处报错,是因为没有引用ComObj单元
可以了~~thx~~
ExcelApp,WorkBook:Olevariant;
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;
这里呢 是不是也是因为我没有引用啊?
引用: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;