打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
用VFP命令控制Word
用VFP命令控制Word
1、创建Word文档
     Appword=CreateObject("word.application")
2、显示Word文档
     Appword.Visible=.t.
3、建立新文档
    Appword.Documents.Add()
4、保存文档
    Appword.ActiveDocument.SaveAs("E:\abc.doc")
5、打开文档
    Appword.ActiveDocument.Open("E:\abc.doc")
6、保存
    Appword.ActiveDocument.Save
7、关闭
    Appword.ActiveDocument.Close
8、退出
    Appword.Application.Quit
9、打印
    Appword.ActiveDocument.PrintOut
10、设置上页边距
    Appword.ActiveDocument.PageSetup.TopMargin=1.5/0.035
11、设置下页边距
    Appword.ActiveDocument.PageSetup.BottomMargin=1.5/0.035
12、设置左页边距
    Appword.ActiveDocument.PageSetup.LeftMargin=1.5/0.035
13、设置右页边距
    Appword.ActiveDocument.PageSetup.RightMargin=1.5/0.035
14、设置页宽
    Appword.ActiveDocument.PageSetup.PageWidth=18.4/0.035
15、设置页高
    Appword.ActiveDocument.PageSetup.PageHeight=26/0.035
16、设置页面竖放
    Appword.ActiveDocument.PageSetup.Orientation=1 
17、设置页面横放
    Appword.ActiveDocument.PageSetup.Orientation=2
18 、指定网格   
    Appword.ActiveDocument.PageSetup.LayoutMode=0    && 0--不指定网格  1--指定网格和字符网格 2--指定行网格 3--文字对齐网格
19、设置每页行数
    Appword.ActiveDocument.PageSetup.LinesPage=42
20、设置每行字数
    Appword.ActiveDocument.PageSetup.ChartLine=10
21、页面设为4栏
    Appword.ActiveDocument.PageSetup.TextColumns.SetCount(4)
22、设置栏宽
    Appword.ActiveDocument.PageSetup.TextColumns.Width=3/0.035
23、设置栏间距
    Appword.ActiveDocument.PageSetup.TextColumns.Specing=0.5/0.035
24、插入文字
    Appword.Selection.Text="如果创建了工具栏"
25、插入文字
    Appword.Selection.InsertAfter(space(6)+"多谢贵公司的支持!")
26、指定字号
   Appword.Selection.FontSize=10.5
27、设置对齐方式
   Appword.Selection.ParagraphFormat.Alignment=0 && 0为左对齐 1居中 2右对齐 3两端对齐
28、设置字体
    Appword.Selection.FontName="宋体"
29、删除光标前面的字符(回车符等)
   Appword.Selection.Typebackspace
30、删除字符
   Appword.Selection.Delete(1,1) && 第一个数字:1为下删一字,2为下删到下一个标点  第二个数字为数量
31、插入新页
    Appword.Selection.InsertBreak(0)
32、回车符
    Appword.Selection.TypeParagraph  && 0--插入新页  1--插入分页符
33、移到上一页的页首
    Appword.Selection.Browser.Previous
34、移到下一页的页首
   Appword.Selection.Browser.Next
35、 Appword.Selection.MoveRight(3,1,1) && 第一个数字意思:3--移动一句,2--移动到上一个标点,1--移动一个字符
                                                                          && 第二个数字为移动的数量    第三个数字表示选中状态
36、Appword.Selection.MoveLeft(3,1,1)
37、Appword.Selection.Moveup(4,1,1)      && 第一个数字:4--移到上一段开头,5--向上移一行,7--翻一页(PageDown)
                                                                         && 第三个数字表示选中状态
38、Appword.Selection.MoveDown(5,1,1)      && 第一个数字:4--移到下一段开头,5--向下移一行,7--下翻一页(PageDown)
                                                                               && 第三个数字表示选中状态
39、选中全部文字
       Appword.Selection. Wholestory
40、插入表格
     Appword..ActiveDocument.Table.Add(Appword.Selection.Range,9,61,0)  && 插入一个9行6列的表格。第三个数字0为没有网格线,1表示有网格线;第四个数字为1时表格自动调整列宽,行宽0时固定列宽,自动调整行宽
41、选定表格一行
     Appword.Selection. SelectRow 
42、选定表格一列
     Appword.Selection. SelectColumn
43、选定表格
     Appword.Selection. Tables(1).Select
44、选定表格所在行高为0.77厘米
    Appword.Selection. Tables(1).RowsHeight=0.77/0.035
45、选定表格所在列宽为2厘米
    Appword.Selection. Tables(1).RowsHeight=2/0.035
46、Appword.Selection. Tables(1).Rows.Alignment=1  && 0为选定表格居左,1时居中,2时居右
47、Appword.Selection. Cells.VerticalAlignment=3       && 选定表格为上对齐,1为居中对齐,2为下对齐 
48、Appword.Selection.ParagraphFormat.Alignment=2  && 选定单元格0为左对齐,1为居中,2为右对齐
49、在第三行第三列插入文字
       Appword.Selection. Tables(1).Row(3).Cell(3).Range.InsertAfter("中国")
50、将选中文字进行分栏操作
      Appword.ActiveDocument.Range(Appword.Selection.Start,  Appword.Selection.Start).InsertBreak(3) 
51、插入图形
     Appword.ActiveDocument.Shape.AddShapes(1,2/0.035,3/0.035,8/0.035,4/0.035) && 插入图形:第一个数字为图形形状,1为矩形,2为平行四边形,3为梯形,各word中基本图形一致,33为箭头总汇第一个,其他类推;第二个数字为图形距面左边位置;第三个数字为图形距面上边位置;第四个数字为图形宽度;第五个数字为图形高度
52、插入直线
     Appword.ActiveDocument.Shapes.AddLine(6/0.035,6/0.035,6/0.035,9/0.035) && 插入直线:前两个数字为起点距页面左、上坐标点,后两个数字为终点距页面左、上坐标点
53、线宽选择
    Appword.Selection.ShapeRange.Line.Weight=0.05/0.035  && 线宽范围必须在选中状态下可用
54、线型选择
    Appword.Selection.ShapeRange.Line.Dashstyle=1 && 线型可选择1--8,共8种
55、把第一行设置为标题行
    WordTable.Rows(1).HeadingFormat=.t.
56、设置第一行高度为1厘米(10毫米)
    WordTable.Rows(1).Height=10*2.835
57、设置框线类型
    WordTable.Borders.Enable=1   && 0--无   1--实  2--其它...
58、设置单元格左间距
    WordTable.LeftPadding=2*2.835
59、设置单元格右间距
    WordTable.RightPadding=2*2.835
60、设置单元格上间距
    WordTable.TopPadding=1*2.835
61、设置单元格下间距
    WordTable.BottomPadding=1*2.835
62、表格水平居中
    WordTable.Rows.HorizontalPosition= - 999995
63、用VFP调用Word模版文档
    Objword=CreateObject("word.application")
    Objword.Visible=.t.
    Objword.Documents.Open("C:\Program Files\Microsoft office\Templates\2052\典雅型信函.dot",0)
64、VFP使用CreateObject命令实现对word文件进行操作的方法
    Public oleApp
    oleApp=CreateObject("word.application")
    oleApp.Visible=.t.
    oleApp.Documents.Add
    oleApp.Selection.TypeText("欢迎光临word世界!")
    oleApp.Documents(1).SaveAs("C:\test.doc")
    oleApp.Quit
65、打印预览
    Appword.ActiveDocument.PrintPreview
66、打印
    Appword.ActiveDocument.PrintOut
67、为word文档添加一个表格
    Appword.ActiveDocuments(1).Tables.Add(Appword.Selection.Range,1,1)
68、在表格的下面重新增加一个表格
    Appword.Selection.MoveDown(5,2,.F.)   && 这里的“5”表示光标向下移动的单位,“2”表示移动的行数,“.F.”布尔型表示是否拓展式移动
    Appword.Selection.TypeParagraph
    Appword.ActiveDocument.Tables.Add(.Appword.Selection.Range,1,1)
69、拆分单元格
    Appword.Documents(1).Tables(2).Cells(1,1).Select
    Appword.Selection.Cells.Split(2,3,.F.)  && 将光标所涉及到的单元格的集合拆分成2行3列
   OR:Appword.Documents(1).Tables(2).Cells(1,1).Split(2,3)
70、合并单元格
    Appword.Documents(1).Tables(2).Cells(1,1).Select
    Appword.Selection.MoveRight(1,3,.T.)  && 光标向右移动3个单位
   Appword.Selection.Cells.Merge
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
VSTOword操作
VBA Word排版 | VBA实例教程
使用 Word (VBA) 分割长图到多页
如何一次性选中WORD文档中的所有表格
处理Selection对象和Range对象——Word VBA中重要的两个对象
VBA 操作word(转载收藏)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服