源码如下:
v:=CreateOleObject('Excel.Application');//创建OLE对象
v.visible:=False;
FileNameString := ExtractFilePath(Application.ExeName) + 'Excel/GranarySystemBook.xls';
if FileExists(FileNameString) then
v.workbooks.Open(FileNameString) //添加工作表
else
begin
MessageDlg('GranarySystemBook.xls 文件不存在!', mtError,[mbOk], 0);
exit;
end;
v.workbooks[1].sheets[1].name:='StoreHouse';
sheet:=v.workbooks[1].sheets['StoreHouse'];
//----------------------------------------
此处添加清空sheet单元格代码
//---------------------------------------
v.WorkBooks[1].Sheets['StoreHouse'].Cells[1,1] := '仓房基本信息记录报表';
v.WorkBooks[1].Sheets['StoreHouse'].Cells[2,1] := '出表日期:' + DateTimeToStr(DateOf(Now));
v.WorkBooks[1].Sheets['StoreHouse'].Cells[3,1] := '仓房编号';
v.WorkBooks[1].Sheets['StoreHouse'].Cells[3,2] := '仓房名称';
v.WorkBooks[1].Sheets['StoreHouse'].Cells[3,3] := '仓房类型';
v.WorkBooks[1].Sheets['StoreHouse'].Cells[3,4] := '仓房长/直径';
v.WorkBooks[1].Sheets['StoreHouse'].Cells[3,5] := '仓房宽/檐高';
v.WorkBooks[1].Sheets['StoreHouse'].Cells[3,6] := '仓房高/顶高';
v.WorkBooks[1].Sheets['StoreHouse'].Cells[3,7] := '角度';
v.WorkBooks[1].Sheets['StoreHouse'].Cells[3,8] := '保管员';
v.WorkBooks[1].Sheets['StoreHouse'].Cells[3,9] := '设计储量';
v.WorkBooks[1].Sheets['StoreHouse'].Cells[3,10] := '实际储量';
v.WorkBooks[1].Sheets['StoreHouse'].Cells[3,11] := '粮食名称';
v.WorkBooks[1].Sheets['StoreHouse'].Cells[3,12] := '入仓日期';
v.WorkBooks[1].Sheets['StoreHouse'].Cells[3,13] := '入仓水分';
v.WorkBooks[1].Sheets['StoreHouse'].Cells[3,14] := '当前水分';
v.WorkBooks[1].Sheets['StoreHouse'].Cells[3,15] := '温度修正值';
v.WorkBooks[1].Sheets['StoreHouse'].Cells[3,16] := '温度上限值';
v.WorkBooks[1].Sheets['StoreHouse'].Cells[3,17] := '温度下限制';
v.WorkBooks[1].Sheets['StoreHouse'].Cells[3,18] := 'RTU编号';
v.WorkBooks[1].Save;
v.Quit;
MessageDlg('数据已经成功输出到Excel表格中!', mtInformation,[mbOk], 0);