从左到右的是最简单,从上到下的稍显复杂
*=================================================================================== *作 用:对指定数据表分栏分组分页 *语 法:ColGroup_Convert(cTableMc,nNumber,cOutTableMc,nMaxColGroupRec) *参数说明:cInTableMc 要转换的数据表,nNumber 分栏分组数, *参数说明:cOutTableMc 分栏分组后的数据表,nMaxColGroupRec 每页每栏的最大记录数(默认为50) *返 回 值:返回生成后的新表(返回表的字段数=分栏数*原字段) *=================================================================================== LPARAMETERS cTableMc,nNumber,cOutTableMc,nMaxColGroupRec LOCAL xfile,xmaxrec,ii,jj,xfieldupd[nNumber],xfields,xrec,xrow,xjs,xcount LOCAL xtime xtime = DATETIME() xfile = SYS(2015) xrec = '' && 结果表结构字段 SELECT &cTableMc FOR jj=1 TO nNumber xfields = '' FOR ii=1 TO FCOUNT() xfields = xfields + ',' + FIELD(ii) + ' F' + TRANSFORM(ii+(jj-1)*FCOUNT()) ENDFOR xrec = xrec + xfields * 生成各栏替换语句xfieldupd[nNumber] xfields = '' FOR ii=1 TO FCOUNT() TEXT TO xfields ADDITIVE PRETEXT 7 NOSHOW TEXTMERGE ,F<<TRANSFORM(ii+(jj-1)*FCOUNT())>> WITH <<cTableMc>>.<<FIELD(ii)>> ENDTEXT ENDFOR xfieldupd[jj] = SUBSTR(xfields,2) ENDFOR xrec = SUBSTR(xrec,2) * 生成结果表 SELECT &xrec FROM &cTableMc WHERE 1=2 INTO CURSOR &cOutTableMc READWRITE SELECT * FROM &cOutTableMc WHERE 1=2 INTO CURSOR &xfile READWRITE && 每页的表,处理结束插入到结果表 xmaxrec = nNumber*nMaxColGroupRec xjs = 1 xrec = 1 xcount = 0 SELECT &cTableMc SCAN IF xjs=1 AND xcount=0 && 计算下一页最大行数 xmaxrec = MIN(xmaxrec,RECCOUNT()-RECNO()+1) xrow = INT(xmaxrec/nNumber) + IIF(MOD(xmaxrec,nNumber)=0,0,1) && 每页行数 ENDIF xcount = xcount + 1 SELECT &xfile IF xjs=1 && 首栏插入 APPEND BLANK ENDIF xfields = xfieldupd[xjs] REPLACE &xfields SKIP IF xcount=xrow && 完成一栏 xcount = 0 xjs = xjs + 1 GO TOP ENDIF IF xjs>nNumber OR RECNO(cTableMc)=RECCOUNT(cTableMc) && 完成一页或者结束了 SELECT &cOutTableMc APPEND FROM DBF(xfile) SELECT * FROM &xfile WHERE 1=2 INTO CURSOR &xfile READWRITE xjs = 1 ENDIF SELECT &cTableMc ENDSCAN USE IN &xfile messagebox( DATETIME()-xtime) RETURN