1. Private Sub Button1_Click(ByVal sender As System.Object, _
  2. ByVal e As System.EventArgs) Handles Button1.Click
  3.  
  4. End Sub
  5. with:
  6. Private Sub Button1_Click(ByVal sender As System.Object, _
  7. ByVal e As System.EventArgs) Handles Button1.Click
  8.  
  9. Dim oWord As Word.Application
  10. Dim oDoc As Word.Document
  11. Dim oTable As Word.Table
  12. Dim oPara1 As Word.Paragraph, oPara2 As Word.Paragraph
  13. Dim oPara3 As Word.Paragraph, oPara4 As Word.Paragraph
  14. Dim oRng As Word.Range
  15. Dim oShape As Word.InlineShape
  16. Dim oChart As Object
  17. Dim Pos As Double
  18.  
  19. 'Start Word and open the document template.
  20. oWord = CreateObject("Word.Application")
  21. oWord.Visible = True
  22. oDoc = oWord.Documents.Add
  23.  
  24. 'Insert a paragraph at the beginning of the document.
  25. oPara1 = oDoc.Content.Paragraphs.Add
  26. oPara1.Range.Text = "Heading 1"
  27. oPara1.Range.Font.Bold = True
  28. oPara1.Format.SpaceAfter = '24 pt spacing after paragraph.
  29. oPara1.Range.InsertParagraphAfter()
  30.  
  31. 'Insert a paragraph at the end of the document.
  32. '** \endofdoc is a predefined bookmark.
  33. oPara2 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
  34. oPara2.Range.Text = "Heading 2"
  35. oPara2.Format.SpaceAfter =
  36. oPara2.Range.InsertParagraphAfter()
  37.  
  38. 'Insert another paragraph.
  39. oPara3 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
  40. oPara3.Range.Text = "This is a sentence of normal text. Now here is a table:"
  41. oPara3.Range.Font.Bold = False
  42. oPara3.Format.SpaceAfter =
  43. oPara3.Range.InsertParagraphAfter()
  44.  
  45. 'Insert a 3 x 5 table, fill it with data, and make the first row
  46. 'bold and italic.
  47. Dim r As Integer, c As Integer
  48. oTable = oDoc.Tables.Add(oDoc.Bookmarks.Item("\endofdoc").Range, , )
  49. oTable.Range.ParagraphFormat.SpaceAfter =
  50. For r = To
  51. For c = To
  52. oTable.Cell(r, c).Range.Text = "r" & r & "c" & c
  53. Next
  54. Next
  55. oTable.Rows.Item().Range.Font.Bold = True
  56. oTable.Rows.Item().Range.Font.Italic = True
  57.  
  58. 'Add some text after the table.
  59. 'oTable.Range.InsertParagraphAfter()
  60. oPara4 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
  61. oPara4.Range.InsertParagraphBefore()
  62. oPara4.Range.Text = "And here's another table:"
  63. oPara4.Format.SpaceAfter =
  64. oPara4.Range.InsertParagraphAfter()
  65.  
  66. 'Insert a 5 x 2 table, fill it with data, and change the column widths.
  67. oTable = oDoc.Tables.Add(oDoc.Bookmarks.Item("\endofdoc").Range, , )
  68. oTable.Range.ParagraphFormat.SpaceAfter =
  69. For r = To
  70. For c = To
  71. oTable.Cell(r, c).Range.Text = "r" & r & "c" & c
  72. Next
  73. Next
  74. oTable.Columns.Item().Width = oWord.InchesToPoints() 'Change width of columns 1 & 2
  75. oTable.Columns.Item().Width = oWord.InchesToPoints()
  76.  
  77. 'Keep inserting text. When you get to 7 inches from top of the
  78. 'document, insert a hard page break.
  79. Pos = oWord.InchesToPoints()
  80. oDoc.Bookmarks.Item("\endofdoc").Range.InsertParagraphAfter()
  81. Do
  82. oRng = oDoc.Bookmarks.Item("\endofdoc").Range
  83. oRng.ParagraphFormat.SpaceAfter =
  84. oRng.InsertAfter("A line of text")
  85. oRng.InsertParagraphAfter()
  86. Loop While Pos >= oRng.Information(Word.WdInformation.wdVerticalPositionRelativeToPage)
  87. oRng.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
  88. oRng.InsertBreak(Word.WdBreakType.wdPageBreak)
  89. oRng.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
  90. oRng.InsertAfter("We're now on page 2. Here's my chart:")
  91. oRng.InsertParagraphAfter()
  92.  
  93. 'Insert a chart and change the chart.
  94. oShape = oDoc.Bookmarks.Item("\endofdoc").Range.InlineShapes.AddOLEObject( _
  95. ClassType:="MSGraph.Chart.8", FileName _
  96. :="", LinkToFile:=False, DisplayAsIcon:=False)
  97. oChart = oShape.OLEFormat.Object
  98. oChart.charttype = 'xlLine = 4
  99. oChart.Application.Update()
  100. oChart.Application.Quit()
  101. 'If desired, you can proceed from here using the Microsoft Graph
  102. 'Object model on the oChart object to make additional changes to the
  103. 'chart.
  104. oShape.Width = oWord.InchesToPoints(6.25)
  105. oShape.Height = oWord.InchesToPoints(3.57)
  106.  
  107. 'Add text after the chart.
  108. oRng = oDoc.Bookmarks.Item("\endofdoc").Range
  109. oRng.InsertParagraphAfter()
  110. oRng.InsertAfter("THE END.")
  111.  
  112. 'All done. Close this form.
  113. Me.Close()
  114.  
  115. End Sub

如何在VB.net中建立word文档的更多相关文章

  1. 如何在程序中给word文档加上标和下标

    如何在程序中给word文档加上标和下标 上标或下标是一个小于普通行格式的数字,图形,标志或者指示通常它的设置与行相比偏上或偏下.下标通常显示于或者低于基准线,而上标则高于.上标和下标通常被用于表达公式 ...

  2. C# 中使用Word文档对图像进行操作

    C# 中使用Word文档对图像进行操作 Download Files: ImageOperationsInWord.zip 简介 在这篇文章中我们可以学到在C#程序中使用一个Word文档对图像的各种操 ...

  3. 在Delphi中处理word文档与数据库的互联 1

    在Delphi中处理word文档与数据库的互联 ---- 目前,Delphi被越来越多的人选中作为MIS系统开发中的前台工具.在以Delphi为前台,一些大型数据库为后台的MIS系统中,图形的处理不可 ...

  4. 在Delphi中处理word文档与数据库的互联

    在Delphi中处理word文档与数据库的互联 ---- 目前,Delphi被越来越多的人选中作为MIS系统开发中的前台工具.在以Delphi为前台,一些大型数据库为后台的MIS系统中,图形的处理不可 ...

  5. c#中操作word文档-四、对象模型

    转自:http://blog.csdn.net/ruby97/article/details/7406806 Word对象模型  (.Net Perspective) 本文主要针对在Visual St ...

  6. c#中操作word文档-一、模板方式写入

    转载自:http://blog.csdn.net/fujie724/article/details/5443322 适合模板写入 今天正好有人问我,怎么生成一个报表式的Word文档. 就是文字的样式和 ...

  7. 在C#中创建word文档

    在下面文档中  首先引用word组件:Microsoft.Office.Interop.Word 在头文件中写上 using Word = Microsoft.Office.Interop.Word; ...

  8. 2.QT中操作word文档

     Qt/Windows桌面版提供了ActiveQt框架,用以为Qt和ActiveX提供完美结合.ActiveQt由两个模块组成: A   QAxContainer模块允许我们使用COM对象并且可以 ...

  9. django admin 中实现word文档下载

    为了实现此功能,需要用到的知识点: (1)django  admin  自定义字段:   参考:http://www.cnblogs.com/wumingxiaoyao/p/6928297.html ...

随机推荐

  1. git教程:管理修改

    转载:管理修改 现在,假定你已经完全掌握了暂存区的概念.下面,我们要讨论的就是,为什么Git比其他版本控制系统设计得优秀,因为Git跟踪并管理的是修改,而非文件. 你会问,什么是修改?比如你新增了一行 ...

  2. bash内建命令

    bash内建命令 1.local命令 基本介绍 local命令是用来定义一个局部变量的,它只能定义在函数中,并且随着函数的结束而被销毁 基本语法 local  [option]  name[=valu ...

  3. mybatis 学习笔记 -详解mybatis 及实例demo

    快速入门1 要点: 首先明白mybatis 是什么 这是一个持久层的框架.之前叫做ibatis.所以,在它的代码中出现ibatis这个词的时候,不要感到惊讶.不是写错了,它确实就是这个样子的. 首先, ...

  4. 8th week blog

    1.indexof() indexOf()的用法:返回字符中indexof(string)中字串string在父串中首次出现的位置,从0开始,没有返回-1:方便判断和截取字符串!indexOf()定义 ...

  5. 添加本地jar包到maven仓库

    mvn install:install-file -Dfile=D:\video-lib\log4j-.jar -DgroupId=video -DartifactId=log4j -Dversion ...

  6. 编程总结5&学习总结

    基础题目 请在第一周作业的基础上,继续完成:找出给定的文件中数组的最大值及其对应的最小下标(下标从0开始).并将最大值和对应的最小下标数值写入文件. 输入:请建立以自己英文名字命名的txt文件,并输入 ...

  7. bat 传递参数

    调用bat时,传递参数有个小问题,记录一下. 1.问题描述: 传递参数时,接收的值不对.传递了“1,2,3”,接收时,只剩下1.后面的没有了. 解决: 原因是bat取参时,语法弄错了. Syntax ...

  8. uwp应用在debug模式下运行正常,编译为release版本的时候抛出异常

    原因是在代码中使用了dynamic关键字,导致release时.net native优化了代码造成元数据丢失 所以在代码中要尽量不用dynamic.

  9. windows7 64位系统安装CPU版本TensorFlow(anaconda3.6)

    1>下载anaconda3.6,https://www.anaconda.com/download/,选择64位的anaconda3.6,安装时候,路径可以自定义,但是要选择把路径添加到环境变量 ...

  10. HBASE 基础命令总结

    HBASE基础命令总结 一,概述 本文中介绍了hbase的基础命令,作者既有记录总结hbase基础命令的目的还有本着分享的精神,和广大读者一起进步.本文的hbase版本是:HBase 1.2.0-cd ...