procedure Tfrm_plan_luoshi.printyl_btnClick(Sender: TObject);
var
exls,sheet,MyWorkBook,xlBook,xlsheet:Variant;
sql1,s,xh,plan_content,create_time,finish,reason:string;
hang,i:integer;
begin
:=crHourGlass; //设置鼠标形状为沙漏状
deletefile('print_00.xls'); //删除临时EXCEL表
copyfile('','print_00.xls',true); //COPY一个模板表
//连接ACCESS数据库
dm1.ADO_access.Connected:=false;
s:=extractfilepath();
dm1.ADO_access.ConnectionString:='Provider=.4.0;Data Source='+s+';Persist Security Info=False';
dm1.ADO_access.Connected:=true;
//清空ACCESS 数据库 print_list表中的数据
ado_access.Close();
ado_access.;
ado_access.('delete * from print_list');
ado_access.ExecSQL;
//把要打印的计划内容写入ACCESS库,print_list表中
sql1:='select ,xh,start_date,end_date,plan_name,plan_content,a.ks_code,a.plan_status,finish,';
sql1:=sql1+'modi_user,create_time,ks_name,lx,reason,c.lx_name ';
sql1:=sql1+' from plan_mana a,plan_ks b,plan_lx c where a.ks_code=b.ks_code and =c.lx_id and plan_status<>''4'' and a.start_date='''++''' and a.end_date='''++''' and a.ks_code=''';
sql1:=sql1+cur_kscode+''' order by xh asc';
ado_query.Close;
ado_query.;
ado_query.(sql1);
ado_query.Open;
while not ado_query.Eof do
begin
plan_content:=ado_query.fieldbyname('plan_content').AsString;
create_time:=ado_query.fieldbyname('create_time').AsString;
finish:=ado_query.fieldbyname('finish').AsString;
reason:=ado_query.fieldbyname('reason').AsString;
xh:=ado_query.fieldbyname('xh').AsString;
ado_access.Close();
ado_access.;
ado_access.('insert into print_list(xh,plan_content,create_time,finish,reason) values('''+xh+''','''+plan_content+''','''+create_time+''','''+finish+''','''+reason+''')');
ado_access.ExecSQL;
ado_query.Next;
end;
写入ACCESS表完成
//开始对EXCEL进行操作
try
s:=extractfilepath();
exls:=createoleobject('');
except
Messagebox(handle,'未发现系统中安装了Microsoft Excel,在使用该功能前,请先将其安装!','错误',mb_ok+mb_iconwarning);
Exit;
end;
(''+s+'print_00.xls');//打开EXCEL临时表
sheet:=createoleobject('');
//sheet:=;
//:=true; //true:EXCE可见 FALSE:不可见会出错的。
//xlsheet:= (1);
清空PRINT—TITLLE表数据
ado_access.Close;
ado_access.;
ado_access.('delete * from print_title');
ado_access.ExecSQL;
/写入PRINT—TITLLE表数据
ado_access.Close;
ado_access.;
ado_access.('insert into print_title(ks_name,time_name_year,time_name_value,time_name_lx) values('''+frm_planmana.selected_ksname+''','''+inttostr(yearof(selected_nd))+''','''+trim()+''','''++' 工作计划'+''')');
ado_access.ExecSQL;
ado_access.Close;
ado_access.;
ado_access.('select * from print_title');
ado_access.open;
///写入EXCEL 表中表头信息
[1,1].value:='安阳市劳动保障服务中心'+ado_access.FieldByName('ks_name').AsString+'工作计划';
[2,3].value:=ado_access.FieldByName('time_name_year').AsString+'年 第'+ado_access.FieldByName('time_name_value').AsString+ado_access.FieldByName('time_name_lx').AsString;
//写入EXCEL表中计划记录
ado_access.Close;
ado_access.;
ado_access.('select * from print_list');
ado_access.open;
hang:=5;
while not ado_access.Eof do
begin
[hang,1].:=1; //边框类型为框
[hang,2].:=1; //边框类型为框
[hang,3].:=1; //边框类型为框
[hang,4].:=1; //边框类型为框
[hang,5].:=1; //边框类型为框
[hang,1].NumberFormatLocal:='@'; // 数据类型设为文本
[hang,2].NumberFormatLocal:='@'; // 数据类型设为文本
[hang,3].NumberFormatLocal:='@'; // 数据类型设为文本
[hang,4].NumberFormatLocal:='@'; // 数据类型设为文本
[hang,5].NumberFormatLocal:='@'; // 数据类型设为文本
[hang,1].:=12; // 数据类型设为文本
[hang,2].:=12; // 数据类型设为文本
[hang,3].:=12; // 数据类型设为文本
[hang,4].:=12; // 数据类型设为文本
[hang,5].:=12; // 数据类型设为文本
[hang,1].HorizontalAlignment:=3;//平行居中
[hang,1].VerticalAlignment:=2;// 垂直居中
[hang,2].VerticalAlignment:=2;//计划内容垂直居中
[hang,5].VerticalAlignment:=2;//未完成原因垂直居中
[hang,1].value:=ado_access.FieldByName('xh').AsString;
[hang,2].value:=ado_access.FieldByName('plan_content').AsString;
[hang,3].value:=ado_access.FieldByName('create_time').AsString;
[hang,4].value:=ado_access.FieldByName('finish').AsString;
[hang,5].value:=ado_access.FieldByName('reason').AsString;
改变行高,为了不太紧
if [hang].RowHeight=14.25 then begin
[hang].RowHeight:=24.25;
end
else if [hang].RowHeight=28.5 then begin
[hang].RowHeight:=38.5;
end
else if [hang].RowHeight=42.75 then begin
[hang].RowHeight:=52.75;
end
else if [hang].RowHeight=57 then begin
[hang].RowHeight:=67;
end
else if [hang].RowHeight=71.25 then begin
[hang].RowHeight:=81.25;
end
else if [hang].RowHeight=85.5 then begin
[hang].RowHeight:=95.5;
end;
hang:=hang+1;
ado_access.Next;
end;
//写入EXCEL中计划记录完成,开始预览或打印
//['A5:b5'].Merge;//合并单元格子的代码
:=true;
;//保存修改
;
;//保存修改
;
:=crDefault; //设置鼠标形状为默认
end;