1. 程式人生 > WINDOWS開發 >delphi 操作excel複製區域功能呢

delphi 操作excel複製區域功能呢

usesComObj;

程式碼很簡單就不用備註了吧

var
ExcelApp:Variant;
c1,c2,r1,r2:Variant;
begin
try
ExcelApp := CreateOleObject(‘Excel.Application‘);
ExcelApp.WorkBooks.Open(‘C:\Users\Administrator\Desktop\ceshi.xlsx‘);
c1 := ExcelApp.ActiveWorkBook.Sheets[1];
c2 := ExcelApp.ActiveWorkBook.Sheets[1];
r1 := c1.range[c2.cells[1,1],c1.cells[1,2]];

r1.select;
r1.copy;
r2 := c2.range[c2.cells[10,10],c2.cells[10,11]];
r2.select;
c2.paste;
finally
ExcelApp.ActiveWorkBook.Saved := true;
ExcelApp.WorkBooks.Close;
ExcelApp.Quit;
end;
end;