首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

excel comojb 操作有关问题

2012-11-04 
excel comojb 操作问题!procedure TForm1.Memo1KeyDown(Sender: TObject var Key: WordShift: TShiftSta

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; //有问题

热点排行