读书人

excel comojb 操作有关问题

发布时间: 2012-11-04 10:42:42 作者: rapoo

excel comojb 操作问题!
procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
i,j,h,l,h2,l2: Integer;
ab: string;
ac: string;
ExcelApp,WorkBook,WorkSheet: Variant;
ExcelApp2,WorkBook2,WorkSheet2: Variant;
begin
if int(key)<>13 then
begin
//if int(key)= 32 then
// begin
// Label5.Caption :=Label5.Caption;
// ShowMessage(Label5.Caption);
// end
// else
// begin
Label5.Caption :=Memo1.Lines.Strings[Memo1.Lines.Count-1];
//end;
end
else
begin
ab:=Label5.Caption;
//Label5.Caption :='';
ExcelApp := CreateOleObject('Excel.Application');
ExcelApp.Visible := false;
WorkBook := ExcelApp.WorkBooks.Open(Edit1.Text);
ExcelApp.WorkSheets[1].Activate;
WorkSheet := WorkBook.WorkSheets.Item[1];
l :=ExcelApp.worksheets[1].Usedrange.columns.count;
h :=ExcelApp.worksheets[1].Usedrange.rows.count;
for i:=1 to h-1 do
begin
for j:= 1 to l-1 do
begin
if Memo1.Lines.Strings[Memo1.Lines.Count-1] = ExcelApp.Cells[i,j].Value then
begin
Memo2.Lines.Add('OK');

//////////////////////////// 有问题 ////////////////////////////////
ExcelApp2 := CreateOleObject( 'Excel.Application' );
ExcelApp2.Visible := false;
WorkBook2 := ExcelApp.WorkBooks.Open(Edit2.Text);
ShowMessage('145553');
ExcelApp2.WorkSheets[1].Activate; //有问题
WorkSheet2 := WorkBook2.WorkSheets.Item[1];
h2 :=ExcelApp2.worksheets[1].Usedrange.rows.count;
ShowMessage(inttostr(h2));
ExcelApp2.ActiveSheet.row.copy(ExcelApp.ActiveSheet.row[i].value);
// myRange1:=sheet.Range[sheet.cells[39,1],sheet.cells[79,16]];
// myRange2:=sheet.Range[sheet.cells[80,1],sheet.cells[120,16]];
//myRange1.Copy(myRange2) ;
continue;
end
else
begin
Memo2.Lines.Add('SN没有扫描到!');
end;

continue;
end;
end;
end;
end;

代码如上,提示的是这句;ExcelApp2.WorkSheets[1].Activate; 有问题。问题提示为:raised exception class EoLeException with message 'OLE error 800A03EC'.请各位大虾指教指教。

[解决办法]
ExcelApp2.Visible := false;
WorkBook2 := ExcelApp2.WorkBooks.Open(Edit2.Text);
ShowMessage('145553');
ExcelApp2.WorkSheets[1].Activate; //有问题

读书人网 >.NET

热点推荐