Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click End Sub
with:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oTable As Word.Table
Dim oPara1 As Word.Paragraph, oPara2 As Word.Paragraph
Dim oPara3 As Word.Paragraph, oPara4 As Word.Paragraph
Dim oRng As Word.Range
Dim oShape As Word.InlineShape
Dim oChart As Object
Dim Pos As Double 'Start Word and open the document template.
oWord = CreateObject("Word.Application")
oWord.Visible = True
oDoc = oWord.Documents.Add 'Insert a paragraph at the beginning of the document.
oPara1 = oDoc.Content.Paragraphs.Add
oPara1.Range.Text = "Heading 1"
oPara1.Range.Font.Bold = True
oPara1.Format.SpaceAfter = '24 pt spacing after paragraph.
oPara1.Range.InsertParagraphAfter() 'Insert a paragraph at the end of the document.
'** \endofdoc is a predefined bookmark.
oPara2 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
oPara2.Range.Text = "Heading 2"
oPara2.Format.SpaceAfter =
oPara2.Range.InsertParagraphAfter() 'Insert another paragraph.
oPara3 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
oPara3.Range.Text = "This is a sentence of normal text. Now here is a table:"
oPara3.Range.Font.Bold = False
oPara3.Format.SpaceAfter =
oPara3.Range.InsertParagraphAfter() 'Insert a 3 x 5 table, fill it with data, and make the first row
'bold and italic.
Dim r As Integer, c As Integer
oTable = oDoc.Tables.Add(oDoc.Bookmarks.Item("\endofdoc").Range, , )
oTable.Range.ParagraphFormat.SpaceAfter =
For r = To
For c = To
oTable.Cell(r, c).Range.Text = "r" & r & "c" & c
Next
Next
oTable.Rows.Item().Range.Font.Bold = True
oTable.Rows.Item().Range.Font.Italic = True 'Add some text after the table.
'oTable.Range.InsertParagraphAfter()
oPara4 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
oPara4.Range.InsertParagraphBefore()
oPara4.Range.Text = "And here's another table:"
oPara4.Format.SpaceAfter =
oPara4.Range.InsertParagraphAfter() 'Insert a 5 x 2 table, fill it with data, and change the column widths.
oTable = oDoc.Tables.Add(oDoc.Bookmarks.Item("\endofdoc").Range, , )
oTable.Range.ParagraphFormat.SpaceAfter =
For r = To
For c = To
oTable.Cell(r, c).Range.Text = "r" & r & "c" & c
Next
Next
oTable.Columns.Item().Width = oWord.InchesToPoints() 'Change width of columns 1 & 2
oTable.Columns.Item().Width = oWord.InchesToPoints() 'Keep inserting text. When you get to 7 inches from top of the
'document, insert a hard page break.
Pos = oWord.InchesToPoints()
oDoc.Bookmarks.Item("\endofdoc").Range.InsertParagraphAfter()
Do
oRng = oDoc.Bookmarks.Item("\endofdoc").Range
oRng.ParagraphFormat.SpaceAfter =
oRng.InsertAfter("A line of text")
oRng.InsertParagraphAfter()
Loop While Pos >= oRng.Information(Word.WdInformation.wdVerticalPositionRelativeToPage)
oRng.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
oRng.InsertBreak(Word.WdBreakType.wdPageBreak)
oRng.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
oRng.InsertAfter("We're now on page 2. Here's my chart:")
oRng.InsertParagraphAfter() 'Insert a chart and change the chart.
oShape = oDoc.Bookmarks.Item("\endofdoc").Range.InlineShapes.AddOLEObject( _
ClassType:="MSGraph.Chart.8", FileName _
:="", LinkToFile:=False, DisplayAsIcon:=False)
oChart = oShape.OLEFormat.Object
oChart.charttype = 'xlLine = 4
oChart.Application.Update()
oChart.Application.Quit()
'If desired, you can proceed from here using the Microsoft Graph
'Object model on the oChart object to make additional changes to the
'chart.
oShape.Width = oWord.InchesToPoints(6.25)
oShape.Height = oWord.InchesToPoints(3.57) 'Add text after the chart.
oRng = oDoc.Bookmarks.Item("\endofdoc").Range
oRng.InsertParagraphAfter()
oRng.InsertAfter("THE END.") 'All done. Close this form.
Me.Close() 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. Cannot create PoolableConnectionFactory (Communications link failure The last packet sent successfu

    SQL: Cannot create JDBC driver of class '' for connect URL 使用数据库数据源的web 项目,发布后,访问数据库500报错: 浏览器端: 控制台 ...

  2. linux为什么要使用CentOS开发?

    CentOS(Community Enterprise Operating System,社区企业操作系统)是Linux发行版之一,它是来自于Red Hat Enterprise Linux依照开放源 ...

  3. liunx学习笔记

    告知-----------------------------------grub启动时滚动的代码屏默认我们执行命令使用的为bash,unix使用的为csh能够通过service 程序名进行start ...

  4. java学习之路重新出发

    一.Java发展史: 1995年由詹姆斯高斯林带领团队开发 java问世 2004  jdk1.5版本更名jdk5.0 2010  sun公司被oracle公司收购  二.java三大体系: java ...

  5. linx6.7 update openssh to 7.7p1

    升级之前需要注意几点: 1 必须要有自己的镜像,必须自己做好本地yum源(可以连接外网,能够有网络yum源也可以) 2 配置好基本的升级环境.在升级openssh时需要依赖openssl和zlib.一 ...

  6. cf352E Jeff and Brackets dp+矩阵快速幂(加法+min运算)

    题意大致是这样的,一共要放 m 段括号序列,每一段放 n 个括号,也就是放 n*m个括号,再每一段中的 n 个位置分别有放左括号和右括号的代价,问最终摆放出合法的括号序列的最小代价是多少. 另外保证, ...

  7. 截取所有的winform runtime error

    https://stackify.com/csharp-catch-all-exceptions/ AppDomain.CurrentDomain.FirstChanceException += (s ...

  8. IDEA中的version control问题

    项目已经添加了svn,但右键项目时找不到Svn选择.但在VCS中却有,很奇怪. 这个问题是svn的根路径与当前IDEA打开的项目路径不一致的原因. 在IdeaProjects下有两个项目,一个inju ...

  9. (转)python爬虫:http请求头部(header)详解

    本文根据RFC2616(HTTP/1.1规范),参考 http://www.w3.org/Protocols/rfc2068/rfc2068 http://www.w3.org/Protocols/r ...

  10. 在Ubuntu15.10中,使用wxPython的webview和JS进行交互

    在Ubuntu下进行wxPython开发,因为需求,所以使用了wxPython的webview和JS的交互. 在Windows下,下图显示的代码可以正常的运行,但是在Ubuntu下进行开发,以下的代码 ...