|
|
#3
王咸美2024-05-23 16:15
具体代码如下:
CLOSE DATABASES
CLEAR ALL
cPath=ADDBS(JUSTPATH(SYS(16)))
SET DEFAULT TO (cPath)
* 随机生成5个题目到EXCEL
USE timu IN 0 ALIAS timu
SELECT timu
replace isc WITH '' all
replace sjs WITH RAND()*1000 all
xt= 5
filecnt=INT(RECCOUNT()/xt)
SET ORDER TO sjs
GO top
FOR i=1 to filecnt
replace isc WITH ALLTRIM(STR(i)) NEXT xt
SKIP
ENDFOR
replace isc WITH ALLTRIM(STR(i)) FOR EMPTY(isc)
filepath="E:\temp1\"
eole=CREATEOBJECT('Excel.Application')
*!* eloe.visible=.t.
*!* 生成 EXCEL
FOR j=1 TO i
SELECT * FROM timu WHERE isc== ALLTRIM(STR(j)) INTO CURSOR temp
IF _tally=0
RETURN
ENDIF
eole.workbooks.Add
eole.worksheets("Sheet1").Activate
lanmu()
excelpath=filepath+"随机选题第"+ALLTRIM(STR(j))+"套.xls"
? '正在生成:'+excelpath
SELECT temp
k=2
SCAN
eole.Cells(k,1)='单选题'
eole.Cells(k,2)=ALLTRIM(tm)+ALLTRIM(tm2)
eole.Cells(k,3)=ALLTRIM(xxa)
eole.Cells(k,4)=ALLTRIM(xxb)
eole.Cells(k,5)=ALLTRIM(xxc)
eole.Cells(k,6)=ALLTRIM(xxd)
eole.Cells(k,8)=ALLTRIM(anwser)
eole.Cells(k,10)='5'
k=k+1
ENDSCAN
eole.ActiveWorkbook.SaveAs(excelpath)
eole.Workbooks.close
ENDFOR
eole.Quit
RELEASE eole
clear
*!* 生成WORD试卷
eole=CREATEOBJECT('word.application')
*!* eole.visible=.t.
FOR j=1 TO i
SELECT * FROM timu WHERE isc== ALLTRIM(STR(j)) INTO CURSOR temp
IF _tally=0
RETURN
ENDIF
eole.Documents.Add
eole.ActiveDocument.PageSetup.TopMargin=1.27/0.035
eole.ActiveDocument.PageSetup.BottomMargin=1.27/0.035
eole.ActiveDocument.PageSetup.LeftMargin=1.27/0.035
eole.ActiveDocument.PageSetup.RightMargin=1.27/0.035
wordname="随机选题第"+ALLTRIM(STR(j))+"套"
? '正在生成:'+wordname
eole.Selection.TypeText(wordname)
eole.Selection.TypeParagraph
SELECT temp
k=1
SCAN
eole.Selection.TypeText(ALLTRIM(STR(k))+"."+ALLTRIM(tm))
eole.Selection.TypeParagraph
IF !EMPTY(tm2)
eole.Selection.TypeText(ALLTRIM(tm2))
eole.Selection.TypeParagraph
ENDIF
xa=ALLTRIM(xxa)
xb=ALLTRIM(xxb)
xc=ALLTRIM(xxc)
xd=ALLTRIM(xxd)
IF LEN(xa+xb+xc+xd)<80
eole.ActiveDocument.Tables.Add(eole.Selection.Range,1,4,0,0)
eole.Selection.Tables(1).Rows(1).Cells(1).Range.InsertAfter(xa)
eole.Selection.Tables(1).Rows(1).Cells(2).Range.InsertAfter(xb)
eole.Selection.Tables(1).Rows(1).Cells(3).Range.InsertAfter(xc)
eole.Selection.Tables(1).Rows(1).Cells(4).Range.InsertAfter(xd)
ELSE
eole.ActiveDocument.Tables.Add(eole.Selection.Range,2,2,0,0)
eole.Selection.Tables(1).Rows(1).Cells(1).Range.InsertAfter(xa)
eole.Selection.Tables(1).Rows(1).Cells(2).Range.InsertAfter(xb)
eole.Selection.Tables(1).Rows(2).Cells(1).Range.InsertAfter(xc)
eole.Selection.Tables(1).Rows(2).Cells(2).Range.InsertAfter(xd)
eole.Selection.MoveDown(5,1,.f.)
ENDIF
eole.Selection.MoveDown(5,1,.f.)
k=k+1
ENDSCAN
eole.ActiveDocument.SaveAs(filepath+wordname+".doc")
eole.ActiveDocument.close
ENDFOR
CLEAR
*!* eole.visible=.t.
FOR j=1 TO i
SELECT * FROM timu WHERE isc== ALLTRIM(STR(j)) INTO CURSOR temp
IF _tally=0
RETURN
ENDIF
eole.Documents.Add
eole.ActiveDocument.PageSetup.TopMargin=1.27/0.035
eole.ActiveDocument.PageSetup.BottomMargin=1.27/0.035
eole.ActiveDocument.PageSetup.LeftMargin=1.27/0.035
eole.ActiveDocument.PageSetup.RightMargin=1.27/0.035
wordname="随机选题第"+ALLTRIM(STR(j))+"套附答案"
? '正在生成:'+wordname
eole.Selection.TypeText(wordname)
eole.Selection.TypeParagraph
SELECT temp
k=1
SCAN
eole.Selection.TypeText(ALLTRIM(STR(k))+"."+ALLTRIM(tm))
eole.Selection.TypeParagraph
IF !EMPTY(tm2)
eole.Selection.TypeText(ALLTRIM(tm2))
eole.Selection.TypeParagraph
ENDIF
xa=ALLTRIM(xxa)
xb=ALLTRIM(xxb)
xc=ALLTRIM(xxc)
xd=ALLTRIM(xxd)
IF LEN(xa+xb+xc+xd)<80
eole.ActiveDocument.Tables.Add(eole.Selection.Range,1,4,0,0)
eole.Selection.Tables(1).Rows(1).Cells(1).Range.InsertAfter(xa)
eole.Selection.Tables(1).Rows(1).Cells(2).Range.InsertAfter(xb)
eole.Selection.Tables(1).Rows(1).Cells(3).Range.InsertAfter(xc)
eole.Selection.Tables(1).Rows(1).Cells(4).Range.InsertAfter(xd)
ELSE
eole.ActiveDocument.Tables.Add(eole.Selection.Range,2,2,0,0)
eole.Selection.Tables(1).Rows(1).Cells(1).Range.InsertAfter(xa)
eole.Selection.Tables(1).Rows(1).Cells(2).Range.InsertAfter(xb)
eole.Selection.Tables(1).Rows(2).Cells(1).Range.InsertAfter(xc)
eole.Selection.Tables(1).Rows(2).Cells(2).Range.InsertAfter(xd)
eole.Selection.MoveDown(5,1,.f.)
ENDIF
eole.Selection.MoveDown(5,1,.f.)
eole.Selection.TypeText("答案:"+ALLTRIM(anwser))
eole.Selection.TypeParagraph
k=k+1
ENDSCAN
eole.ActiveDocument.SaveAs(filepath+wordname+".doc")
eole.ActiveDocument.close
ENDFOR
eole.Quit
RELEASE eole
MESSAGEBOX("导出完毕")
PROCEDURE lanmu
eole.cells(1,1)='题型'
eole.cells(1,2)='题目'
eole.cells(1,3)='选项1'
eole.cells(1,4)='选项2'
eole.cells(1,5)='选项3'
eole.cells(1,6)='选项4'
eole.cells(1,7)='选项5'
eole.cells(1,8)='答案'
eole.cells(1,9)='解析'
eole.cells(1,10)='分值'
|