ปัญหาคือมีรายงานบางตัวที่ต้องใช้สคริปกับ tempreport เขียน เพื่อจะเอาข้อมูลออกมาเป็น Exel
ทีนี้พอติ๊กถูกส่งออกข้อมูลเป็น Exel ปรากฎว่าแต่ละฟิลขยายเต็มจอเลยครับ (ฟิลที่เป็น name) ต้องเสียเวลามาลดขนาดฟิล
ก็เลยอยากถามว่า มีคำสั่งอะไรที่ทำให้รายงาน ส่งออกเป็น Exel แล้วความกว้างของฟิลพอดีกับข้อมูลเลย
เบื้องต้นใช้ substr ให้ตัดข้อความให้สั้นลงก่อน แต่ก็จะมีปัญหาถ้ามีข้อมูลบางตัวที่ยาวเกินอีก
เคยลองใช้ Print to file ก็พบปัญหาว่าคอลัมมันไม่ค่อยตรงกันครับ
รบกวน อ.ทั้งหลาย ช่วยชี้แนะด้วยครับ
//////////////////////////
SQL
/////////////////////////
select
substr(name1,1,10) as hn,
substr(name2,1,40) as pt_name,
substr(name3,1,3) as age_y,
substr(name4,1,3) as FBS,
substr(name5,1,3) as BW,
substr(name6,1,3) as HT,
substr(name7,1,8) as BP,
substr(name8,1,10) as BMI,
substr(name9,1,30) as result,
substr(name10,1,3) as w,
substr(name11,1,30) as result_charonic,
date1 as vstdate
from tempreport t1
where t1.id = "CUSTOM-NUKE"
//////////////////////////////////////////
Script
/////////////////////////////////////////
//==============================================================
// @Author : Nattapong Roadmuang
// @Date : 2010 March 10
// @HOSxP : 3.53.3.12
// @MySQL : 5.1.30
// @OS : Microsoft Windows 7 Ultimate
// @Hospital : Phromphiram Phitsanulok
//==============================================================
unit ImNuke_Report;
//==========================================================
// Make subquery data
// @param sql : SQL
// @return result : Data from query (subquerydata format)
//==========================================================
function getsqlsubquerydata(sql:string):string;
begin
result:='';
zquery.close;
zquery.sql.text:=sql;
zquery.open;
zquery.first;
while not zquery.eof do
begin
if result='' then result:=''''+zquery.fields[0].asstring+'''' else
result:=result+','''+zquery.fields[0].asstring+'''';
zquery.next;
end;
zquery.close;
if result='' then result:='''''';
end;
//==========================================================
// Main Procedure
//==========================================================
procedure main;
var d1,d2:tdatetime;
ds1,ds2,fvn,sender:string;
i:Interger;
begin
// 1. Clear Tempreport
zquery.sql.text:='delete from tempreport where id = "CUSTOM-NUKE" ';
zquery.execsql;
fcds.close;
fcds.datarequest('select * from tempreport where id = "CUSTOM-NUKE" ');
fcds.open;
// 2. Select date range
if not getdaterange() then exit;
d1:=date_result1();
d2:=date_result2();
ds1:=formatdatetime('yyyy-mm-dd',d1);
ds2:=formatdatetime('yyyy-mm-dd',d2);
// 3. Select Register
inputquery('ÃËÑʼÙéÊ觵ÃǨ','loginname',sender);
// 4. Select visit list
fvn := getsqlsubquerydata('select vn from opd_regist_sendlist where staff="'+sender+'" and date(send_datetime) between "'+ds1+'" and "'+ds2+'"');
// 5. Query Data
fcds2.close;
fcds2.datarequest('select v.vn,v.age_y,v.hn,v.vstdate,concat(p.pname,p.fname," ",p.lname) as ptname,p.sex as sex,v.vstdate,'+
' (select waist from opdscreen o where o.vn=v.vn) as w, '+
' (select bw from opdscreen o1 where o1.vn=v.vn) as bw, ' +
' (select height from opdscreen o2 where o2.vn=v.vn) as height,'+
' (select concat(round(bps,0),"/",round(bpd,0)) from opdscreen o3 where o3.vn=v.vn) as BP,'+
' (select round(bps,0) from opdscreen o4 where o4.vn=v.vn) as BPS,'+
' (select round(bpd,0) from opdscreen o5 where o5.vn=v.vn) as BPD,'+
' round((select bmi from opdscreen o4 where o4.vn = v.vn),2) as bmi, ' +
' (select l2.lab_order_result from lab_order l2,lab_head l1 where l1.vn=v.vn and l2.lab_order_number = l1.lab_order_number and l2.lab_items_code="76" ) as FBS'+
' from vn_stat v,patient p '+
' where v.hn=p.hn and v.vn in ('+fvn+') order by hn');
fcds2.open;
if fcds2.recordcount=0 then
begin
showmessage('No Data');
exit;
end
fcds2.first;
// Pack Data
while not fcds2.eof do
begin
fcds.insert;
fcds['id']:='CUSTOM-NUKE';
fcds['reportname']:='CUSTOM-NUKE';
fcds['name1'] := fcds2['hn']; // HN
fcds['name2'] := fcds2['ptname']; // NAME
fcds['name3'] := fcds2['age_y']; // AGE_Y
fcds['name4'] := fcds2['FBS']; // FBS
fcds['name5'] := fcds2['bw']; // BW
fcds['name6'] := fcds2['height']; // HT
fcds['name7'] := fcds2['bp']; // BP
fcds['name8'] := fcds2['bmi']; // BMI
fcds['name10'] := fcds2['w']; // Waist
fcds['date1'] := fcds2['vstdate']; // Vstdate
// Result
if fcds2['bmi'] < 18.5 then
fcds['name9'] := '¼ÍÁ'
else if fcds2['bmi'] <=23 then
fcds['name9'] := '»¡µÔ'
else if fcds2['bmi'] <=25 then
fcds['name9'] := '¤è͹¢éÒ§Íéǹ'
else if fcds2['bmi'] <=30 then
fcds['name9'] := 'ÍéǹÃдѺ 1'
else if fcds2['bmi'] > 30 then
fcds['name9'] := 'ÍéǹÃдѺ 2';
// Result_Chronic
if ((fcds2['w'] >= 80) and (fcds2['sex'] = '2')) or ((fcds2['w'] >= 90) and (fcds2['sex'] = '1')) then
fcds['name11'] := 'àÊÕè§'
else if (fcds2['BPS'] > 140 or fcds2['BPD'] > 90) then
fcds['name11'] := 'àÊÕè§'
else if (fcds2['FBS'] > 126 ) then
fcds['name11'] := 'àÊÕè§'
else
fcds['name11'] := 'äÁèàÊÕè§';
fcds2.next;
fcds.post;
end;
fcds.datarequest('select * from tempreport where id = "CUSTOM-NUKE" ');
applyupdate_fcds();
end;
end.