procedure TForm1.Button1Click(Sender: TObject);
var ExcelApp: Variant;
Sheet: Variant;
i,h:integer;
j,aa,bb,cc:integer;
sheetname:string;
begin
aa:=strtoint(trim(Edit1.Text));
bb:=strtoint(trim(edit2.Text));
cc:=(bb-aa);
h:=1;
try
ExcelApp := CreateOleObject('Excel.Application');
ExcelApp.Visible := false;
ExcelApp.Caption := '应用程序调用 Microsoft Excel';
ExcelApp.WorkBooks.Open( 'C:/222.xls' ); //打开已存在的工作簿
Except
ExcelApp.Free;
exit;
end;
while cc>0 do
begin
sheetname:='sheet'+inttostr(h);
Sheet :=ExcelApp.Workbooks[1].WorkSheets[sheetname];
j:=0;
while j<7 do
begin
for i:=0 to 3 do
begin
sheet.cells[j+1, i + 1]:= '0'+inttostr(aa);
aa:=aa+1;
end;
inc(j);
end;
cc:=cc-28;
h:=h+1;
end;
excelapp.Visible := True;
ShowMessage('ok!');
end;