如何按班级、按模板格式批量生成WORD表格
现有 成绩汇总表.dbf、模板文件cjtjmb.doc,如何按班级、按模板格式批量生成WORD表格(各班成绩统计表)?请高手帮忙,万分感谢!!!
成绩汇总表.zip
(6.64 KB)
成绩汇总表.dbf
模板文件cjtjmb.doc
生成的样表
CLEAR CLOSE TABLES ALL PUBLIC cpath as String LOCAL iArr1 as Integer ,iMax as Integer cpath = 'c:\XIDE\Projects\' && 成绩表和模板文件所在的文件夹。 iMax = 60 && 模板文件可装入人数的最大值。 USE (cpath + '成绩汇总表.DBF') IN 0 SELECT 班级 ,COUNT(*) as 人数 FROM 成绩汇总表 GROUP BY 班级 INTO ARRAY arrbanji FOR iArr1 = 1 TO ALEN( arrbanji ,1) IF arrbanji[iArr1 ,2] > iMax THEN WAIT arrbanji[iArr1 ,1] + '共' + LTRIM(STR(arrbanji[iArr1 ,2])) + ; '人,人数超出模板文件限制,请重新制定模板。程序将跳过制作该班汇总表。' WINDOW AT 10 ,20 TIMEOUT 3 ELSE WAIT arrbanji[iArr1 ,1] + '共' + LTRIM(STR(arrbanji[iArr1 ,2])) + ; '人,程序开始制作该班汇总表。。。' WINDOW AT 10 ,20 NOWAIT SELECT 姓名,语文,数学,英语 FROM 成绩汇总表 INTO ARRAY arrcj where 班级 = arrbanji[iArr1 ,1] = MakeDoc(arrbanji[iArr1 ,1] ,@arrcj) RELEASE arrcj ENDIF NEXT iArr1 USE IN 成绩汇总表 WAIT CLEAR MESSAGEBOX('制作完成,共输出' + LTRIM(STR(ALEN( arrbanji ,1))) + '个文件。',64,'成绩汇总表') RELEASE arrbanji PROCEDURE MakeDoc(bjmc ,arrcj2) LOCAL oApp as Object ,oDoc as Object ,oTab as Object LOCAL cWordFile as String ,cFileOut as String LOCAL iside ,iCol , iRow , ii as Integer STORE 0 TO iside ,iCol , iRow , ii cWordFile = cpath + 'cjtjmb.doc' && 模板文件 cFileOut = cpath + bjmc && 输出文件 oApp = CREATEOBJECT('Word.Application') oDoc = oApp.Documents.Open(cWordFile,0,.t.) oTab = oDoc.Tables(1) For iside = 1 To 2 For irow = 2 To oTab.Rows.Count IF ii < ALEN(arrcj2 ,1 ) THEN For icol = 1 To 4 oTab.cell(irow, icol + 4 * (iside - 1)).Range.Text = arrcj2(irow + 30 * (iside - 1) - 1, icol) Next icol ii = ii + 1 ELSE EXIT ENDIF Next irow Next iside IF FILE(cFileOut) THEN DELETE FILE &cFileOut ENDIF odoc.SaveAs2(cFileOut) oDoc.Close() oApp.Quit() ENDPROC
[此贴子已经被作者于2022-1-1 15:21编辑过]