王宏健的专栏 ---- 健康快乐

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::
//Excel的单元格拷贝粘贴

procedure Excel_copyCells;
var
  sheet,XLApp,workbook,myRange1 ,myRange2: variant;
begin
  try
    //创建对象
    XLApp:=createOleObject('Excel.Application');
      XLApp.displayAlerts:=true;
      XLApp.ScreenUpdating:=true;
    XLApp.visible:=true;
    XLApp.WorkBooks.Add('D:\Test.xls');
    workbook := XLApp.workbooks[1];
    sheet:=workbook.worksheets[1];
    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) ;
  finally
    if not VarIsEmpty(XLApp) then begin
      XLApp.displayAlerts:=false;
      XLApp.ScreenUpdating:=true;
      XLApp.quit;
    end;
  end;
end;
posted on 2004-11-29 17:02  LuckyJan  阅读(736)  评论(0)    收藏  举报