delphi 操作excel复制区域功能呢

uses ComObj;

代码很简单就不用备注了吧

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;

delphi 操作excel复制区域功能呢

上一篇:win10好用的桌面工具分享+网盘下载链接


下一篇:C#读取Excel五种方式的体会