作者在 2015-11-29 18:19:00 发布以下内容
* 测试表
CREATE CURSOR T (BH C(4),B1 N(4),B2 N(4),B3 N(4),B4 N(4))
INSERT INTO T VALUES ([0001],1200,1000,800,600)
INSERT INTO T VALUES ([0002],1100,900,700,500)
INSERT INTO T VALUES ([0003],1900,1700,1500,1300)
SELECT *,000000 小计 FROM T INTO CURSOR TEMP READWRITE
LCSTR=[]
* 生成字段名列表
FOR I=2 TO FCOUNT()-1
LCSTR=LCSTR+FIELD(I)+IIF(I<FCOUNT()-1,[+],[])
ENDFOR
* 行小计
REPLACE ALL 小计 WITH &LCSTR
* 列合计
INSERT INTO TEMP ((FIELD(1))) VALUES (PADC("合计",FSIZE(FIELD(1)),"-"))
FOR I=2 TO FCOUNT()
IF TYPE(FIELD(I))="N"
SUM EVALUATE(FIELD(I)) TO HJ
*--- 数值型字段求和,并将结果添加到最后一条记录
REPLACE RECORD RECCOUNT() (FIELD(I)) WITH HJ IN TEMP
ENDIF
ENDFOR
SELECT TEMP
BROWSE