注册 登录
编程论坛 VFP论坛

当word表格不满一页时,原页脚内容自动上移到表格下面

王咸美 发布于 2025-05-27 16:12, 229 次点击
当word表格不满一页时,原页脚内容自动上移到表格下面,下列代码如何修改,请高手赐教,万分感谢!!!
只有本站会员才能查看附件,请 登录

只有本站会员才能查看附件,请 登录


附VFP代码(待修改)
CLOSE DATABASES
CLEAR ALL
SET TALK OFF
SET SAFETY OFF
SET MARK TO "-"
SET CENTURY on
SET COMPATIBLE off
FN=GETFILE("dbf")
USE &FN

WAIT "正在访问word软件..." WINDOW nowait
wordApp=CREATEOBJECT("word.Application")

WAIT "正在生成表格......" WINDOW nowait
wordApp.Visible=.t.
wordApp.Documents.Add
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
 
# define NUM_AFIELDS 16
PUBLIC aWizFList
DIMENSION aWizFList[1]
=AFIELDS(aWizFList)

LOCAL mytextzhi
GO top
myfcount=FCOUNT()
FOR i=1 TO  FCOUNT()
  IF INLIST(aWizFList[i,2],"G","M")
     myfcount=myfcount-1
     LOOP
   ENDIF
ENDFOR
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,RECCOUNT()+1,myfcount)
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.Rows(1).Range.Font.Bold=.t.
wordTable.Rows(1).Cells.VerticalAlignment=1
wordTable.Rows(1).Range.Paragraphs.Alignment=4
wordTable.Rows(1).HeadingFormat=.t.

FOR j=1 TO RECCOUNT()
  k=0
  FOR i=1 TO FCOUNT()
   IF INLIST(aWizFList[i,2],"G","M")
     k=k+1
     LOOP
   ELSE
     myzdm=aWizFList[i,1]
     mytextzhi=EVALUATE(myzdm)
     IF EMPTY(mytextzhi) OR ISNULL(mytextzhi)
       mytextzhi=" "
     ELSE
       DO case
          CASE INLIST(aWizFList[i,2],"C")
             mytextzhi=ALLTRIM(mytextzhi)
          CASE INLIST(aWizFList[i,2],"M")
             mytextzhi=TRIM(mytextzhi)
             mytextzhi=STRTRAN(mytextzhi,CHR(13),' ')
          CASE INLIST(aWizFList[i,2],"N")
             myWidth=aWizFList[i,3]
             mydWidth=aWizFList[i,4]
             mytextzhi=ALLTRIM(STR(mytextzhi,myWidth,mydWidth))
          CASE INLIST(aWizFList[i,2],"Y")
             mytextzhi=ALLTRIM(STR(mytextzhi,20,4))
          CASE INLIST(aWizFList[i,2],"I","B","F")
             mytextzhi=ALLTRIM(STR(mytextzhi))
          CASE aWizFList[i,2]="D"
             mytextzhi=DTOC(mytextzhi)
          CASE aWizFList[i,2]="T"
             mytextzhi=TTOC(mytextzhi)
          CASE aWizFList[i,2]="L"
            IF mytextzhi=.T.
              mytextzhi="是"
            ELSE
              mytextzhi="否"
            ENDIF
          other=" "
       ENDCASE
       IF EMPTY(mytextzhi) OR ISNULL("mytextzhi")
         mytextzhi=" "
       ENDIF
       wordTable.cell(1,i-k).range.Text=aWizFList[i,1]
       wordTable.Rows(j+1).cells(i-k).range.insertafter(mytextzhi)
     ENDIF
   ENDIF
  NEXT i
  SKIP 1
NEXT j
wordTable.Columns().AutoFit

* 下面为页面设置
wordApp.ActiveDocument.PageSetup.PaperSize=7
wordApp.ActiveDocument.PageSetup.Orientation=0
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
wordApp.ActiveDocument.PageSetup.FooterDistance=19.0*2.835
wordApp.Documents(1).Sections(1).Footers(1).Range.Paragraphs.Alignment=2
wordApp.Documents(1).Sections(1).Footers(1).Range.select
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.InsertAfter("页")
wordApp.Selection.Range.Paragraphs.Alignment=1
wordTable.Rows(1).HeadingFormat=.t.
wordTable.Columns().AutoFit
wordApp.Documents(1).SaveAs("E:\"+ALIAS()+".doc")
wordApp.Quit
RELEASE wordApp
WAIT clear
MESSAGEBOX("生成word文件完毕,文件位置E:\"+ALIAS()+".doc!",64,"完毕")
RETURN








[此贴子已经被作者于2025-5-27 17:27编辑过]

3 回复
#2
schtg2025-05-27 17:45
页脚,应该在页面下面页脚本身所处的位置,咋会不够一页时就跑到了表格的下面。若是这样的话,那么设置的就不是页脚吧
#3
王咸美2025-05-27 18:27
不设置页脚,在每页表格下面写上 第x页/共y页 如何做到?望指点!
#4
王咸美2025-05-30 12:31
假设毎页打印35条记录,有没有办法在每页表格下面插入页码,请高手指点,谢谢!
1