标签:
上回借机房收费系统讲到了用vb.net导出Excel,这次在做项目的过程中,我们不仅学会了将数据打印到VS自带的报表中,还了解了如何用vb.net操作word,将窗体中的内容反映到word中。所以今天要向大家分享一下如何用VB.net 导出word,生成word报表。Imports Microsoft.Office.Interop
Dim oword As Word.Application Dim odoc As Word.Document Dim otable As Word.Table Dim opara1 As Word.Paragraph Dim opara2 As Word.Paragraph Dim opara3 As Word.ParagraphParagraph 对象代表所选内容、范围或文档中的一个段落。Paragraph 对象是 Paragraphs 集合的一个成员。Paragraphs 集合包含所选内容、范围或文档中的所有段落。
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click oword = CreateObject("Word.application") oword.Visible = True odoc = oword.Documents.Add odoc.PageSetup.Orientation = Word.WdOrientation.wdOrientLandscape '横向显示,试用于横向打印 opara1 = odoc.Content.Paragraphs.Add opara1.Range.Text = "人才资源状况调查统计表" opara1.Range.Font.Bold = True opara1.Format.SpaceAfter = 25 '在段落之后24 Pt 空格 opara1.Range.Font.Size = 18 '字号为18 opara1.Format.SpaceBefore = 2 '段间距为2 opara1.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter '居中显示 opara1.Range.InsertParagraphAfter() '段后显示 otable = odoc.Tables.Add(odoc.Bookmarks.Item("\endofdoc").Range, 7, 3) '表格为7行3列 otable.Range.ParagraphFormat.SpaceAfter = 6 otable.Cell(1, 1).Range.Text = "填报单位:" otable.Cell(2, 1).Range.Text = "负责人:" otable.Cell(3, 1).Range.Text = "填表人:" otable.Cell(4, 1).Range.Text = "报出时间:" otable.Cell(5, 1).Range.Text = "联系电话:" otable.Cell(1, 2).Range.Text = TextBox1.Text.ToString otable.Cell(1, 2).Range.Underline = Word.WdUnderline.wdUnderlineWords '添加下划线 otable.Cell(2, 2).Range.Text = TextBox2.Text.ToString otable.Cell(2, 2).Range.Underline = Word.WdUnderline.wdUnderlineWords otable.Cell(3, 2).Range.Text = TextBox3.Text.ToString otable.Cell(3, 2).Range.Underline = Word.WdUnderline.wdUnderlineWords otable.Cell(4, 2).Range.Text = Now.Year & "年" & Now.Month & "月" & Now.Day & "日" otable.Cell(4, 2).Range.Underline = Word.WdUnderline.wdUnderlineWords otable.Cell(5, 2).Range.Text = TextBox4.Text otable.Cell(5, 2).Range.Underline = Word.WdUnderline.wdUnderlineWords otable.Cell(6, 2).Range.Text = "部门组织部" otable.Cell(7, 2).Width = 250 otable.Cell(7, 2).Range.Text = "人力资源管理企业" otable.Cell(1, 3).Range.Text = "(盖章)" otable.Cell(2, 3).Range.Text = "(签字)" otable.Cell(3, 3).Range.Text = "(签字)" otable.Cell(6, 3).Range.Text = "(制)" otable.Cell(7, 3).Range.Text = Now.Year & "年" & Now.Month & "月" End Sub
标签:
原文地址:http://blog.csdn.net/wkx18330698534/article/details/51338947