📄 excelunit.pas
字号:
strrcj:string;
m_break:boolean;
ntoprcj,nbreak:integer;
nbreakcount:integer;
nrow:integer;
nl:integer;
ntmppage1:integer;
begin
if (getactiveform as TFrm_ys).tv_js.Selected<>nil then
strselectid:=PData2((getactiveform as TFrm_ys).tv_js.Selected.Data)^.ID
else
abort;
getxx(strselectid); //取得报表基本信息
setxx(strselectid,(getactiveform as TFrm_ys).temp_grid); //给临时的grid赋值
gethjsb;
if Trim(array_jbxx[1])='1' then
nl:=1
else
nl:=0;
nh:=0;
nb:=0;
nw:=0;
ntemp:=0;
nxm:=300;
nxmh:=strtoint(array_jbxx[48]);
ntopdis:=strtoint(array_jbxx[5])*3;
nbottomdis:=strtoint(array_jbxx[7])*3;
nleftdis:=strtoint(array_jbxx[4])*3;
nrightdis:=strtoint(array_jbxx[6])*3;
for i:=0 to (getactiveform as TFrm_ys).temp_grid.ColCount-1 do
ntemp:=ntemp+(getactiveform as TFrm_ys).temp_grid.ColWidths[i];
if Trim(array_jbxx[1])='1' then //表头框架的宽度
nw:=ntemp
else
nw:=ntemp-(getactiveform as TFrm_ys).temp_grid.ColWidths[0];
nhheight:=gethead((getactiveform as TFrm_ys).temp_grid,strtoint(array_jbxx[48])); // strtoint(array_jbxx[48])
if Trim(array_jbxx[8])='1' then
begin
dx:=getpagew(0,True);
dy:=getpageh(0,True);
end
else
begin
dx:=getpagew(0,False);
dy:=getpageh(0,False);
end;
// nwidth:=dx-nleftdis-nrightdis; //报表实际宽度
nheight:=dy-ntopdis-nbottomdis; //报表实际高度
nh:=getup(array_jbxx[26],array_jbxx[27],array_jbxx[28],array_jbxx[29],array_jbxx[30],array_jbxx[31],array_jbxx[32],array_jbxx[33],array_jbxx[34]);
nb:=getup(array_jbxx[35],array_jbxx[38],array_jbxx[41],array_jbxx[36],array_jbxx[39],array_jbxx[42],array_jbxx[37],array_jbxx[40],array_jbxx[43]);
ntop:=ntopdis+60+nh; //表头开始离纸的高度
nbottomtop:=dy-nbottomdis-nb; //作为换页的依据;
ntmppage1:=0;
for i:=0 to jsblist.Count-1 do
begin
ntempcount:=0;
djfx:=Tjc_rcj(jsblist.Items[i]);
strrcj:=Trim(djfx.column1);
geteachrcj(strrcj);
if Trim(array_dyxx[7])='1' then
begin
if Trim(array_jbxx[8])='1' then
begin
while ntempcount<=rclist.Count-1 do
begin
ntoprcj:=nxmh*5;
nbreak:=ntop+ntoprcj;
for k:=ntempcount to rclist.Count-1 do
begin
rcj:=Trcjj(rclist.Items[k]);
nmax:=1;
nmax:=getmaxstr(nmax,60,rcj.r_bh);
nmax:=getmaxstr(nmax,160,rcj.r_mc);
nmax:=getmaxstr(nmax,60,rcj.r_unit);
nmax:=getmaxstr(nmax,70,currtostr(rcj.r_dj));
nmax:=getmaxstr(nmax,70,currtostr(rcj.r_market));
nmax:=getmaxstr(nmax,70,floattostr(rcj.r_sl));
nmax:=getmaxstr(nmax,75,currtostr(rcj.r_dj*rcj.r_sl));
nmax:=getmaxstr(nmax,dx-nleftdis-nrightdis-625,currtostr(rcj.r_market*rcj.r_sl));
nbreak:=nbreak+nxmh*nmax;
if nbreak+30>nbottomtop then
break;
ntempcount:=k+2;
// inc(h);
end; //for rclist
inc(ntmppage1);
end; //end; //while
end //if Trim(array_jbxx[8])='1' then
else //if Trim(array_jbxx[8])='0' then
begin
ntempcount:=0;
while ntempcount<=rclist.Count-1 do
begin
ntoprcj:=nxmh*5;
nbreak:=ntop+ntoprcj;
for k:=ntempcount to rclist.Count-1 do
begin
rcj:=Trcjj(rclist.Items[k]);
nmax:=1;
nmax:=getmaxstr(nmax,80,rcj.r_bh);
nmax:=getmaxstr(nmax,290,rcj.r_mc);
nmax:=getmaxstr(nmax,80,rcj.r_unit);
nmax:=getmaxstr(nmax,100,currtostr(rcj.r_dj));
nmax:=getmaxstr(nmax,100,currtostr(rcj.r_market));
nmax:=getmaxstr(nmax,100,floattostr(rcj.r_sl));
nmax:=getmaxstr(nmax,100,currtostr(rcj.r_dj*rcj.r_sl));
nmax:=getmaxstr(nmax,dx-nleftdis-nrightdis-900,currtostr(rcj.r_market*rcj.r_sl));
nbreak:=nbreak+nxmh*nmax;
if nbreak+30>nbottomtop then
break;
ntempcount:=k+2;
end; //for rclist
inc(ntmppage1);
end; //end; //while
end; //end; if Trim()='0'
end //if Trim(array_dyxx[1])='1' then
else if Trim(array_dyxx[8])='1' then
begin
ntempcount:=0;
while ntempcount<rclist.Count-1 do
begin
nbreak:=ntop+nhheight;
for k:=ntempcount to rclist.Count-1 do
begin
nmax:=1;
for c:=1 to (getactiveform as TFrm_ys).temp_grid.ColCount-1 do
begin
nmin:=getlinecount(caleachrcj(k,(getactiveform as TFrm_ys).temp_grid,c),(getactiveform as TFrm_ys).temp_grid.ColWidths[c]);
if nmin>nmax then
nmax:=nmin;
end;
nbreak:=nbreak+nxmh*nmax;
if nbreak+30>nbottomtop then
break;
ntempcount:=k+2;
end;
inc(ntmppage1);
end; //end while ntempcount<jclist.Count-1 do
end; //end if Trim()='1'
end; //end; //for count
npagecount:=ntmppage1;
//初始化数据
LinkExcel;
try
mainform.ExcelWorksheet1.PageSetup.BottomMargin:=nbottomdis;
mainform.ExcelWorksheet1.PageSetup.TopMargin:=ntopdis;
mainform.ExcelWorksheet1.PageSetup.LeftMargin:=nleftdis;
mainform.ExcelWorksheet1.PageSetup.RightMargin:=nrightdis;
if Trim(array_jbxx[8])='0' then
mainform.ExcelWorksheet1.PageSetup.Orientation:=xlLandscape;
mainform.ExcelApplication1.Range['A1','A1'].ColumnWidth:=1;
nrow:=0; npagetmp:=0;
for i:=0 to jsblist.Count-1 do
begin
ntempcount:=0;
djfx:=Tjc_rcj(jsblist.Items[i]);
strrcj:=Trim(djfx.column1);
//取得该条定额的人材机的数据
geteachrcj(strrcj);
if Trim(array_dyxx[7])='1' then
begin
if Trim(array_jbxx[8])='1' then
begin
while ntempcount<=rclist.Count-1 do
begin
if nrow=0 then
nrow:=1
else
nrow:=nrow+getlinex(0)+1;
//把表头导到
npagetmp:=npagetmp+1;
if array_dyxx[7]='1'then
djfxbttoExcel(nrow)
else if array_dyxx[8]='1' then
ExportbzstoExcel((getactiveform as TFrm_ys).temp_grid,nrow);
nrow:=nrow+2+getline(0);
setdjfxbt('B','C','定额编号',xlCenter,xlCenter,nrow,110,True);
setdjfx('D','G',djfx.column2,xlCenter,xlLeft,nrow,True);
setdjfx('H','J','序号:'+inttostr(djfx.flag),xlCenter,xlRight,nrow,True); //第一
mainform.ExcelApplication1.Range['B'+inttostr(nrow),'J'+inttostr(nrow)].Borders.LineStyle:=xlContinuous;
setdjfx('B','C','定额名称',xlCenter,xlCenter,nrow+1,True);
setdjfx('D','J',djfx.column7,xlCenter,xlLeft,nrow+1,True); //第二
mainform.ExcelApplication1.Range['B'+inttostr(nrow+1),'J'+inttostr(nrow+1)].Borders.LineStyle:=xlContinuous;
setdjfx('B','C','定额单位',xlCenter,xlCenter,nrow+2,True);
setdjfx('D','J',djfx.column8,xlCenter,xlLeft,nrow+2,True); //第三
mainform.ExcelApplication1.Range['B'+inttostr(nrow+2),'J'+inttostr(nrow+2)].Borders.LineStyle:=xlContinuous;
setdjfx('B','C','定额基价',xlCenter,xlCenter,nrow+3,True);
setdjfx('D','E',djfx.column14+' (元)',xlCenter,xlLeft,nrow+3,True);
setdjfx('F','G','市场基价',xlCenter,xlCenter,nrow+3,True);
setdjfx('H','J',djfx.column20+' (元)',xlCenter,xlLeft,nrow+3,True);
mainform.ExcelApplication1.Range['B'+inttostr(nrow+3),'J'+inttostr(nrow+3)].Borders.LineStyle:=xlContinuous;
setdjfxbt('B','B','编号',xlCenter,xlCenter,nrow+4,60,False);
setdjfxbt('C','D','项目名称',xlCenter,xlCenter,nrow+4,175,True);
setdjfxbt('E','E','单位',xlCenter,xlCenter,nrow+4,60,False);
setdjfxbt('F','F','定额单价',xlCenter,xlCenter,nrow+4,80,False);
setdjfxbt('G','G','市场单价',xlCenter,xlCenter,nrow+4,80,False);
setdjfxbt('H','H','数量',xlCenter,xlCenter,nrow+4,70,False);
setdjfxbt('I','I','定额合价',xlCenter,xlCenter,nrow+4,80,False);
setdjfxbt('J','J','市场合价',xlCenter,xlCenter,nrow+4,dx-nleftdis-nrightdis-605,False);
mainform.ExcelApplication1.Range['B'+inttostr(nrow+4),'J'+inttostr(nrow+4)].Borders.LineStyle:=xlContinuous;
nrow:=nrow+5;
ntoprcj:=nxmh*5;
nbreak:=ntop+ntoprcj;
for k:=ntempcount to rclist.Count-1 do
begin
rcj:=Trcjj(rclist.Items[k]);
nmax:=1;
nmax:=getmaxstr(nmax,60,rcj.r_bh);
nmax:=getmaxstr(nmax,175,rcj.r_mc);
nmax:=getmaxstr(nmax,60,rcj.r_unit);
nmax:=getmaxstr(nmax,70,currtostr(rcj.r_dj));
nmax:=getmaxstr(nmax,70,currtostr(rcj.r_market));
nmax:=getmaxstr(nmax,70,floattostr(rcj.r_sl));
nmax:=getmaxstr(nmax,75,currtostr(rcj.r_dj*rcj.r_sl));
nmax:=getmaxstr(nmax,dx-nleftdis-nrightdis-625,currtostr(rcj.r_market*rcj.r_sl));
setdjfxbt('B','B',rcj.r_bh,xlCenter,xlCenter,nrow,60,False);
setdjfxbt('C','D',rcj.r_mc,xlCenter,xlCenter,nrow,175,True);
setdjfxbt('E','E',rcj.r_unit,xlCenter,xlCenter,nrow,60,False);
setdjfxbt('F','F',currtostr(rcj.r_dj),xlCenter,xlCenter,nrow,80,False);
setdjfxbt('G','G',currtostr(rcj.r_market),xlCenter,xlCenter,nrow,80,False);
setdjfxbt('H','H',floattostr(rcj.r_sl),xlCenter,xlCenter,nrow,70,False);
setdjfxbt('I','I',currtostr(rcj.r_dj*rcj.r_sl),xlCenter,xlCenter,nrow,80,False);
setdjfxbt('J','J',currtostr(rcj.r_market*rcj.r_sl),xlCenter,xlCenter,nrow,dx-nleftdis-nrightdis-605,False);
mainform.ExcelApplication1.Range['B'+inttostr(nrow),'J'+inttostr(nrow)].Borders.LineStyle:=xlContinuous;
nrow:=nrow+1;
mainform.statusbar1.Panels[2].Text:='正在检查数据并导入到Excel['+inttostr(i+1)+'/'+inttostr(rclist.Count)+'],请稍候....................';
mainform.StatusBar1.Update;
nbreak:=nbreak+nxmh*nmax;
if nbreak+30>nbottomtop then
break;
end;
ntempcount:=k+1;
bzxtoExcel((getactiveform as TFrm_ys).temp_grid,nrow+1);
end; //while ntempcount<rclist.Count-1 do
end //if Trim(array_jbxx[8])='1' then
else
begin
while ntempcount<rclist.Count-1 do
begin
if nrow=0 then
nrow:=1
else
nrow:=nrow+getlinex(0)+1;
//把表头导到
ExportbzstoExcel((getactiveform as TFrm_ys).temp_grid,nrow);
nrow:=nrow+2+getline(0);
setdjfxbt('B','C','定额编号',xlCenter,xlCenter,nrow,160,True);
setdjfx('D','G',djfx.column2,xlCenter,xlLeft,nrow,True);
setdjfx('H','J','序号:'+inttostr(djfx.flag),xlCenter,xlRight,nrow,True); //第一
mainform.ExcelApplication1.Range['B'+inttostr(nrow),'J'+inttostr(nrow)].Borders.LineStyle:=xlContinuous;
setdjfx('B','C','定额名称',xlCenter,xlCenter,nrow+1,True);
setdjfx('D','J',djfx.column7,xlCenter,xlLeft,nrow+1,True); //第二
mainform.ExcelApplication1.Range['B'+inttostr(nrow+1),'J'+inttostr(nrow+1)].Borders.LineStyle:=xlContinuous;
setdjfx('B','C','定额单位',xlCenter,xlCenter,nrow+2,True);
setdjfx('D','J',djfx.column8,xlCenter,xlLeft,nrow+2,True); //第三
mainform.ExcelApplication1.Range['B'+inttostr(nrow+2),'J'+inttostr(nrow+2)].Borders.LineStyle:=xlContinuous;
setdjfx('B','C','定额基价',xlCenter,xlCenter,nrow+3,True);
setdjfx('D','E',djfx.column14+' (元)',xlCenter,xlLeft,nrow+3,True);
setdjfx('F','G','市场基价',xlCenter,xlCenter,nrow+3,True);
setdjfx('H','J',djfx.column20+' (元)',xlCenter,xlLeft,nrow+3,True);
mainform.ExcelApplication1.Range['B'+inttostr(nrow+3),'J'+inttostr(nrow+3)].Borders.LineStyle:=xlContinuous;
setdjfxbt('B','B','编号',xlCenter,xlCenter,nrow+4,80,False);
setdjfxbt('C','D','项目名称',xlCenter,xlCenter,nrow+4,290,True);
setdjfxbt('E','E','单位',xlCenter,xlCenter,nrow+4,80,False);
setdjfxbt('F','F','定额单价',xlCenter,xlCenter,nrow+4,100,False);
setdjfxbt('G
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -