如何简化代码(自动生成含有任课教师姓名的各班级课表)
如何简化下列程序代码,自动生成含有任课教师姓名的各个班级课表?请高手赐教!CLEAR ALL
CLOSE ALL
SET TALK OFF
SET SAFETY OFF
SET DATE TO YMD
SET MARK TO "-"
SET CENTURY ON
SET COMPATIBLE OFF
cCurrentProcedure = SYS(16,1)
nPathStart =AT(":",cCurrentProcedure)- 1
nLenOfPath = RAT("\",cCurrentProcedure) - (nPathStart)
mypath=SUBSTR(cCurrentProcedure,nPathStart, nLenofPath)
SET Default TO (mypath)
wjm=mypath+ "\bjkbmb3.doc" && 班级课程表模板(含有标题行的空表)
PUBLIC cnj,cbj,cxkmc,i
WordApp=CREATEOBJECT("Word.application")
WordApp.Visible =.t.
SELECT 0
USE jsrkb alia bjb
SCAN
cnj=bjb.nj
cbj=bjb.bj
WAIT WINDOW '正在生成“ ' +cnj+ cbj+ ' ”的日课表……' NOWAIT
SELECT * from rkzb201803 where nj=cnj and bj=cbj into table bjkb
SELECT bjkb
WordTable=WordApp.Application.Documents.Open(wjm) && 关键
wordapp.selection
wordapp.Selection.InsertAfter(ALLTRIM("&cnj&cbj")) && 在模板文件标题行插入年级、班级
WordTable.Tables.item(1).Cell(2,3).Range.Text=bjkb.Zhou11
cxkmc=ALLTRIM(bjkb.zhou11)
SELECT bjb
FOR i=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(3,3).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(4,3).Range.Text=bjkb.Zhou12
cxkmc=ALLTRIM(bjkb.zhou12)
SELECT bjb
FORi=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(5,3).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(6,3).Range.Text=bjkb.Zhou13
cxkmc=ALLTRIM(bjkb.zhou13)
SELECT bjb
FOR i=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(7,3).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(8,3).Range.Text=bjkb.Zhou14
cxkmc=ALLTRIM(bjkb.zhou14)
SELECT bjb
FOR i=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(9,3).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(10,3).Range.Text=bjkb.Zhou15
cxkmc=ALLTRIM(bjkb.zhou15)
SELECT bjb
FOR i=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(11,3).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(12,3).Range.Text=bjkb.Zhou16
cxkmc=ALLTRIM(bjkb.zhou16)
SELECTbjb
FOR i=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(13,3).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(2,4).Range.Text=bjkb.Zhou21
cxkmc=ALLTRIM(bjkb.zhou21)
SELECT bjb
FOR i=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(3,4).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(4,4).Range.Text=bjkb.Zhou22
cxkmc=ALLTRIM(bjkb.zhou22)
SELECT bjb
FOR i=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(5,4).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(6,4).Range.Text=bjkb.Zhou23
cxkmc=ALLTRIM(bjkb.zhou23)
SELECT bjb
FOR i=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(7,4).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(8,4).Range.Text=bjkb.Zhou24
cxkmc=ALLTRIM(bjkb.zhou24)
SELECT bjb
FOR i=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(9,4).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(10,4).Range.Text=bjkb.Zhou25
cxkmc=ALLTRIM(bjkb.zhou25)
SELECT bjb
FOR i=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(11,4).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(12,4).Range.Text=bjkb.Zhou26
cxkmc=ALLTRIM(bjkb.zhou26)
SELECT bjb
FOR i=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(13,4).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(2,5).Range.Text=bjkb.Zhou31
cxkmc=ALLTRIM(bjkb.zhou31)
SELECT bjb
FOR i=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(3,5).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(4,5).Range.Text=bjkb.Zhou32
cxkmc=ALLTRIM(bjkb.zhou32)
SELECT bjb
FOR i=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(5,5).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(6,5).Range.Text=bjkb.Zhou33
cxkmc=ALLTRIM(bjkb.zhou33)
SELECT bjb
FOR i=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(7,5).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(8,5).Range.Text=bjkb.Zhou34
cxkmc=ALLTRIM(bjkb.zhou34)
SELECT bjb
FOR i=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(9,5).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(10,5).Range.Text=bjkb.Zhou35
cxkmc=ALLTRIM(bjkb.zhou35)
SELECT bjb
FOR i=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(11,5).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(12,5).Range.Text=bjkb.Zhou36
cxkmc=ALLTRIM(bjkb.zhou36)
SELECT bjb
FOR i=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(13,5).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(2,6).Range.Text=bjkb.Zhou41
cxkmc=ALLTRIM(bjkb.zhou41)
SELECT bjb
FOR i=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(3,6).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(4,6).Range.Text=bjkb.Zhou42
cxkmc=ALLTRIM(bjkb.zhou42)
SELECT bjb
FOR i=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(5,6).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(6,6).Range.Text=bjkb.Zhou43
cxkmc=ALLTRIM(bjkb.zhou43)
SELECT bjb
FOR i=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(7,6).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(8,6).Range.Text=bjkb.Zhou44
cxkmc=ALLTRIM(bjkb.zhou44)
SELECT bjb
FOR i=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(9,6).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(10,6).Range.Text=bjkb.Zhou45
cxkmc=ALLTRIM(bjkb.zhou45)
SELECT bjb
FOR i=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(11,6).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(12,6).Range.Text=bjkb.Zhou46
cxkmc=ALLTRIM(bjkb.zhou46)
SELECT bjb
FOR i=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(13,6).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(2,7).Range.Text=bjkb.Zhou51
cxkmc=ALLTRIM(bjkb.zhou51)
SELECT bjb
FOR i=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(3,7).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(4,7).Range.Text=bjkb.Zhou52
cxkmc=ALLTRIM(bjkb.zhou52)
SELECT bjb
FOR i=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(5,7).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(6,7).Range.Text=bjkb.Zhou53
cxkmc=ALLTRIM(bjkb.zhou53)
SELECT bjb
FOR i=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(7,7).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(8,7).Range.Text=bjkb.Zhou54
cxkmc=ALLTRIM(bjkb.zhou54)
SELECT bjb
FORi=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(9,7).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(10,7).Range.Text=bjkb.Zhou55
cxkmc=ALLTRIM(bjkb.zhou55)
SELECT bjb
FOR i=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(11,7).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
WordTable.Tables.item(1).Cell(12,7).Range.Text=bjkb.Zhou56
cxkmc=ALLTRIM(bjkb.zhou56)
SELECT bjb
FOR i=1 to FCOUNT()
IF FIELD(i)=cxkmc
WordTable.Tables.item(1).Cell(13,7).Range.Text=EVALUATE(FIELD(i))
ENDIF
ENDFOR
filename=mypath+ "\"+ cnj +cbj+ "课程表.doc"
WordApp.Documents(1).SaveAs(filename) &&自动保存文件
WordApp.ActiveDocument.Close
SELECT bjkb
USE
SELECT bjb
WAIT CLEAR
ENDSCAN
wordapp.application.quit
MESSAGEBOX("班级日课表的word文档,生成完毕!",64,"提示:")
QUIT