下列程序如何修改才能达到样表的格式要求,请高手赐教,万分感谢!!!
SET TALK OFF
SET SAFETY OFF
SET DATE TO YMD
SET MARK TO "-"
SET CENTURY ON
SET COMPATIBLE OFF
use maths20170522.dbf IN 0 ALIAS maths
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
*WordApp.ActiveDocument.PageSetup.LinesPage = 48
&&设置每页打印行数
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)
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=9
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.
m=0
FOR i=1 TO FCOUNT()
if INLIST(aWizFList[i,2],"G","M")
m=m+1
loop
endif
WordTable.Cell(1,i-m).Range.Text=aWizFList[i,1]
FOR k=2 TO RECCOUNT()+1
GO k-1
if INLIST(aWizFList[i,2],"G","M")
m=m+1
loop
else
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-m).Range.Text=WordCellText
endif
ENDFOR
WordTable.Columns().AutoFit
endfor
* 下面为页面设置
WordApp.ActiveDocument.PageSetup.PaperSize=7
WordApp.ActiveDocument.PageSetup.Orientation=0 &&页面竖放 0-竖放
1-横放
*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-下
WordTable.Columns().AutoFit
&&自动调整列宽
WordTable.Columns().AutoFit
* 自动保存文件
WordApp.Documents(1).SaveAs("E:\"+alias()+".doc")
&&自动保存文件
RELEASE WordApp
WAIT CLEAR
MessageBox( "生成Word文件完毕,文件位置 E:\"+alias()+".doc!",64,"完毕")
RETURN