@xuminxz 我把程序及问题截图发上来,请帮我看看代码有什么问题?
程序代码如下:
* VFP调用WORD模板文件生成多页WORD文档
* 设置"标题行重复":打开新生成的WORD文档,选中标题行->单击表格->单击标题行重复
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="F:\temp2\股票信息统计表模板.doc"
WordApp=CREATEOBJECT("Word.application")
WordApp.Visible =.t.
WordTable=WordApp.Application.Documents.Open[wjm] && 关键
use gp.dbf
WordApp.ActiveDocument.Tables(1).Cell(3,1).Select
WordApp.Selection.InsertRowsBelow(RECCOUNT()-1) && 插入行
FOR i=1 TO FCOUNT()
FOR k=3 TO RECCOUNT()+2 && word模板表头有2行
GO k-2
WordCellText=EVALUATE(FIELD(i))
DO CASE
CASE ISNULL(WordCellText)
WordCellText=""
CASE TYPE("WordCellText")="N"
CASE TYPE("WordCellText")="D"
WordCellText=DTOC(WordCellText)
CASE TYPE("WordCellText")="T"
WordCellText=TTOC(WordCellText)
CASE TYPE("WordCellText")="M"
WordCellText=TRIM(WordCellText)
WordCellText=STRTRAN(WordCellText,CHR(13),' ')
CASE TYPE("WordCellText")="L"
WordCellText=IIF(WordCellText,".T.",".F.")
CASE EMPTY(WordCellText)
WordCellText=" "
OTHERWISE
* WordCellText=""
ENDCASE
IF EMPTY(WordCellText) OR ISNULL(WordCellText)
WordCellText=" "
ENDIF
WordTable.Tables.Item(1).Cell(k,i).Range.Text=WordCellText
ENDFOR
ENDFOR
yms=INT(RECCOUNT()/20)
FOR i=1 TO yms
WordApp.ActiveDocument.Tables(1).Cell(i*20+4,1).Select
WordApp.Selection.InsertBreak(7)
ENDFOR
WordApp.ActiveDocument.PageSetup.FooterDistance=19.0*2.835 &&页脚位置
*WordApp.ActiveDocument.PageSetup.Footer.fontsize=12
*mydate=subst(dtos(date()),1,4)+"年"+subst(dtos(date()),5,2)+;
*"月"+subst(dtos(date()),7,2)+"日"
*WordApp.Documents(1).Sections(1).Headers(1).Range.Text="制表日期: ;
*"+mydate+" " &&页
WordApp.Documents(1).Sections(1).Headers(1).Range.Paragraphs.Alignment=2 && 页眉右齐
WordApp.Documents(1).Sections(1).Footers(1).Range.Paragraphs.Alignment=1 && 页脚居中
WordApp.Documents(1).Sections(1).Footers(1).Range.Select
WordApp.Selection.Font.Size=12
WordApp.Selection.InsertAfter("第")
WordApp.Selection.Start =WordApp.Selection.End
WordApp.Selection.InsertFormula("PAGE")
WordApp.Selection.Start =WordApp.Selection.End
WordApp.Selection.InsertBefore("页/共")
WordApp.Selection.Start =WordApp.Selection.End
WordApp.Selection.InsertFormula("NUMPAGES")
WordApp.Selection.Start =WordApp.Selection.End
WordApp.Selection.InsertBefore("页")
WordApp.Documents(1).SaveAs("F:\temp2\股票信息统计表.doc") &&自动保存文件
RELEASE WordApp
WAIT CLEAR
MessageBox( "生成Word文件完毕,文件位置 F:\temp2\股票信息统计表.doc!",64,"完毕")
RETURN