第一步,添加引用:
第二步:引用声明
Imports Microsoft.Office.Interop
第三步:详细代码:
声明:
在这里我为了完成我的表,用来三个paragraph对象,如上:opara1,opara2,opara3.
编辑表内信息
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