模板文件要为.xlt格式
try
CoInitialize(nil);
FExcelapp := CreateOleObject('Excel.Application');
except
raise Exception.Create('请确认MicroSoft Excel已安装并能正常运行!');
Exit;
end;
try
fWorkBook := FExcelapp.WorkBooks.Add('模板文件路径')
except
on E: Exception do begin
fmessage := fmessage + ' 打开Excel模板出错 ';
raise;
end;
end;
导出数据:
fWorkBook.activesheet.Range['A10'].value := 2000;
finally
fWorkBook.saveas(savedir+ '.xls');
fWorkBook.saved := true;
fWorkBook.close;
FExcelapp.Quit;
FExcelapp := Unassigned;
end;