求助:下列程序循环语句有问题,请高手指点!
teacher.rar
(1.29 KB)
下列程序循环语句有问题,请高手指点,万分感谢!!!
【要求生成的word表格每页打印20条记录,不足以空行补足,结果第二页少一条记录,
第三页少两条记录,第四页少三条,不知为何?请赐教!】
有问题的语句如下:
FOR ii=1 to mPAGE &&&
aa=(ii-1)*xx+ii
bb=(ii-1)*xx
cc=ii*xx
FOR i=1 TO FCOUNT()
* WordTable.Cell(1,i).Range.Text=FIELD(i)
WordTable.Cell(aa,i).Range.Text=FIELD(i)
* FOR k=2 TO RECCOUNT()+1
FOR k=aa+1 TO cc+1
IF k>RECCOUNT()+1
EXIT
ENDIF
GO k-1
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.Cell(k,i).Range.Text=WordCellText
【原代码如下】
fn=getfile("dbf")
use "&fn" IN 0
IF EMPTY(ALIAS())
MessageBox( "当前工作区没有打开工作表!",48,"不能生成表格")
ENDIF
WAIT "正在访问 Word 软件……" WINDOW NOWAIT
WordApp=CREATEOBJECT("Word.application") &&访问WORD
If Type("WordApp")#"O"
WAIT CLEAR
MessageBox( "访问Word失败!请检查你的系统是否正确安装 Word 软件!",48,"没有安装Word")
RETURN
ENDIF
WAIT "正在生成表格……" WINDOW NOWAIT
WordApp.Visible =.t.
WordApp.Documents.Add
XX=20
mI=RECCOUNT() % XX
m=xx-mI
n=RECCOUNT()+m
mPAGE=N/XX
nCount=RECCOUNT()+m+mPAGE
* WordApp.ActiveDocument.PageSetup.PageWidth=18.4/0.035 &&设置页宽
* WordApp.ActiveDocument.PageSetup.PageHeight=26/0.035 &&设置页高
* WordApp.ActiveDocument.PageSetup.LinesPage = 35 &&设置每页打印行数
WordApp.Documents(1).Range.Text=ALIAS()+"一览表"
WordApp.Documents(1).Range.Font.Size= 15
WordApp.Documents(1).Range.Font.Name="黑体"
WordApp.Documents(1).Range.Paragraphs.Alignment= 1
WordAppRang=WordApp.Documents(1).Range(LENC(WordApp.Documents(1).Range.Text)-1,LENC(WordApp.Documents(1).Range.Text)-1)
WordTable=WordApp.Documents(1).Tables.Add(WordAppRang,nCount+1,FCOUNT())
WordTable.Range.Paragraphs.Alignment= 0
WordTable.Range.Font.Name="宋体"
WordTable.Range.Font.Size=10
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.Borders.OutsideLineWidth=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 ii=1 to mPAGE &&&
aa=(ii-1)*xx+ii
bb=(ii-1)*xx
cc=ii*xx
FOR i=1 TO FCOUNT()
* WordTable.Cell(1,i).Range.Text=FIELD(i)
WordTable.Cell(aa,i).Range.Text=FIELD(i)
* FOR k=2 TO RECCOUNT()+1
FOR k=aa+1 TO cc+1
IF k>RECCOUNT()+1
EXIT
ENDIF
GO k-1
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.Cell(k,i).Range.Text=WordCellText
endfor
WordTable.Columns(i).AutoFit
endfor
ENDFOR &&& NEXT ii
* 下面为页面设置
WordApp.ActiveDocument.PageSetup.PaperSize=7
WordApp.ActiveDocument.PageSetup.Orientation=0 &&页面竖放 0-竖放 1-横放
yms=n/xx
FOR i=1 to yms-1
WordApp.ActiveDocument.Tables(i).Cell(22,1).select
Wordapp.selection.InsertBreak(7)
ENDFOR
*WordTable.Rows.HorizontalPosition=-999995 &&表格水平居中
WordApp.ActiveDocument.PageSetup.TopMargin=22.0*2.835 &&设置上边距
WordApp.ActiveDocument.PageSetup.BottomMargin=22.0*2.835 &&设置下边距
WordApp.ActiveDocument.PageSetup.LeftMargin=19.0*2.835 &&设置左边距
WordApp.ActiveDocument.PageSetup.RightMargin=19.0*2.835 &&设置右边距
WordApp.ActiveDocument.PageSetup.VerticalAlignment=0 &&页面对齐方式 0-上 1-中 2-下
WordApp.Documents(1).SaveAs("E:\My.doc") &&自动保存文件
RELEASE WordApp
WAIT CLEAR
MessageBox( "生成Word文件完毕,文件位置 E:\My.doc !",64,"完毕")
RETURN
[此贴子已经被作者于2024-8-23 15:57编辑过]