谢谢SDTA版主的帮助,确定有帮助。读完你给的程序代码,我修改了我的源程序,但是运行还有报错,
图片附件: 游客没有浏览图片的权限,请
登录 或
注册
这是运行程序打开的DBF文件
程序代码:
SET TALK OFF
SET SAFETY Off
CLOSE ALL
CLEAR ALL
CLEAR
WAIT "请打开存放当年学位数据的数据。。。。。"
USE ?
Word=CREATEOBJECT('word.application') &&创建WORD文档
Word.Visible=.t. &&显示WORD文档
Word.Documents.add() &&建立新文档
Word.ActiveDocument.PageSetup.TopMargin=2/0.035 &&设置上页边距
Word.ActiveDocument.PageSetup.BottomMargin=2/0.035 &&设置下页边距
Word.ActiveDocument.PageSetup.LeftMargin=2/0.035 &&设置左页边距
Word.ActiveDocument.PageSetup.RightMargin=2/0.035 &&设置右页边距
INDEX on xy TO xh1 uniq
COPY TO ARRAY xy1 FIELDS xy
SET INDEX TO
FOR J=1 TO ALEN(xy1,1)
COUNT FOR xy=xy1(J,1) TO zrs
INDEX on zymc TO zymc1 uniq
COPY TO ARRAY zymc1 FIELDS zymc FOR xy=xy1(J,1)
SET INDEX TO
Word.Selection.Font.Size = 15 &&指定字号,9为小五号,10.5为五号,12为小四号
Word.Selection.Font.Name = "黑体" &&设置字体
word.Selection.ParagraphFormat.Alignment=1
word.Selection.TypeParagraph
word.selection.typetext(ALLTRIM(xy1(J,1))+ALLTRIM(STR(YEAR(DATE())))+'情况报告单')
word.Selection.TypeParagraph
word.Selection.TypeParagraph
Word.Selection.Font.Size = 13.5 &&指定字号,9为小五号,10.5为五号,12为小四号
Word.Selection.Font.Name = "仿宋_GB2312" &&设置字体
word.Selection.ParagraphFormat.Alignment=0
word.selection.typetext(SPACE(4)+ALLTRIM(xy1(j,1))+"届"+ALLTRIM(STR(ALEN(zymc1,1)))+"个专业共"+ALLTRIM(STR(zrs))+"人,其中")
FOR i=1 TO ALEN(zymc1,1)
COUNT FOR zymc=zymc1(i,1) TO rs1
word.selection.typetext(ALLTRIM(zymc1(i,1))+ALLTRIM(STR(rs1))+"人,")
ENDFOR
COUNT FOR DELETED() AND xy=xy1(j,1) TO brs
word.selection.typetext("共"+ALLTRIM(STR(brs))+"人不能授予学位。")
LOCATE FOR DELETED() AND xy=xy1(J,1)
IF FOUND()
word.selection.typetext("不能授予学位名单如下:")
COPY TO d:\ls FOR xy=xy1(j,1) AND DELETED() FIELDS xh,xm,bz1
SELECT 10
USE d:\ls
WordRang=Word.Documents(1).Range(LENC(Word.Documents(1).Range.Text)-1,LENC(Word.Documents(1).Range.Text)-1) &&运行这语句循环第二次就报错,错误信息如上图
WordTable=Word.Documents(1).Tables.Add(WordRang,RECCOUNT()+1,FCOUNT())
WordTable.Range.Paragraphs.Alignment= 0
WordTable.Range.Font.Name="宋体"
WordTable.Range.Font.Size=11
WordTable.Borders.Enable=1 &&设置表格网格线型
WordTable.Borders(1).LineWidth = 12 &&设置表格第顶端线宽
WordTable.Borders(2).LineWidth = 12 &&设置表格第底端线宽
WordTable.Borders(3).LineWidth = 12
WordTable.Borders(4).LineWidth = 12 &&设置表格第右侧线宽
WordTable.Rows(1).Borders(3).LineWidth = 12 &&设置标题下端线宽
WordTable.Rows(1).Range.Font.Bold=.T.
WordTable.Rows(1).Cells.VerticalAlignment= 1
WordTable.Rows(1).Range.Paragraphs.Alignment = 1
WordTable.Rows(1).HeadingFormat=.t.
For lnI=1 To Fcount()
WordTable.Cell(1,lnI).Range.Text=Field(lnI)
For lnJ=2 TO Reccount()+1
Go lnJ-1
WordCellText=EVALUATE(FIELD(lnI))
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 Empty(WordCellText)
WordCellText=""
Otherwise
* WordCellText=""
Endcase
WordTable.Cell(lnJ,lnI).Range.Text=WordCellText
Next
* WordTable.Columns(lnI).AutoFit
Next
WordTable.Rows.HorizontalPosition=-999995 && 表格水平居中
word.Application.Browser.Next
Word.Selection.InsertBreak(1)
RELEASE ZYMC1
USE IN 10
ENDIF
SELECT 1
ENDFOR
word.Selection.WholeStory
word.Selection.ParagraphFormat.LineSpacingRule = 4
Word.Selection.ParagraphFormat.LineSpacing = 17
RETURN
我这个程序是基本功能是循环输出多个学院的情况报告单,但是在处理第二个学院时就出现上面的报错信息。麻烦各位大侠帮我看看如何解决。