vb.net word html,VB.NET 创建WORD文档

'''

''' 创建word文档

'''

'''

Public Sub CreateDoc()

Dim docApp As New Word.Application

Dim doc As Word.Document

Dim miss As Object = System.Reflection.Missing.Value

doc = docApp.Documents.Add(miss,miss,miss)

Dim strContext As String = ""

'文件内容

strContext = "你好,我简单的幸福."

'行距

docApp.Selection.ParagraphFormat.LineSpacing = 15

'页眉

With docApp

.ActiveWindow.View.Type = Word.WdViewType.wdOutlineView

.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader

.ActiveWindow.ActivePane.Selection.InsertAfter("[页眉内容]")

.Selection.Paragraphs.Alignment = WdParagraphAlignment.wdAlignParagraphRight

.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument '跳出页眉设置

End With

'页尾

With docApp

.ActiveWindow.View.Type = Word.WdViewType.wdOutlineView

.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryFooter

.ActiveWindow.ActivePane.Selection.InsertAfter("[页尾内容]")

.Selection.Paragraphs.Alignment = WdParagraphAlignment.wdAlignParagraphRight

.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument

End With

'表格

Dim table As Word.Table = doc.Tables.Add(docApp.Selection.Range,10,3)

'表格样式

With table

.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleSingle

.Borders.InsideLineStyle = WdLineStyle.wdLineStyleSingle

.Columns(1).Width = 100

.Columns(2).Width = 220

.Columns(3).Width = 105

End With

'填充表格内容

With table

.Cell(1,1).Range.Text = "产品详细信息表"

.Cell(1,1).Range.Bold = 2 '粗体

.Cell(1,1).Range.Font.Color = WdColor.wdColorBrown

'合并单元格

.Cell(1,1).Merge(.Cell(2,3)) '横向合并

End With

With docApp.Selection

.Cells.VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter '垂直居中

.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter '水平居中

End With

With table

.Cell(2,1).Range.Text = "品牌名称:"

.Cell(3,1).Range.Text = "史丹奴"

End With

'纵向合并单元格

table.Cell(3,3).Select() '选中一行

Dim moveUnit As Object = Word.WdUnits.wdLine

Dim moveCount As Object = 5

Dim moveExtend As Object = WdMovementType.wdExtend

With docApp

.Selection.MoveDown(moveUnit,moveCount,moveExtend)

.Selection.Cells.Merge()

End With

'插入图片

Dim strPicPath As String = "http://www.google.com.hk/intl/zh-CN/images/logo_cn.png"

Dim linkToFile As Object = False

Dim saveWithDoc As Object = True

Dim anchor As Object = doc.Application.Selection.Range

With doc.Application.ActiveDocument

.InlineShapes.AddPicture(strPicPath,linkToFile,saveWithDoc,anchor)

.InlineShapes(1).Width = 100 '图片宽度

.InlineShapes(1).Height = 100 '图片高度

End With

'设置图片为四周环绕型

Dim s As Word.Shape

s = doc.Application.ActiveDocument.InlineShapes(1).ConvertToShape()

s.WrapFormat.Type = WdWrapType.wdWrapSquare

'添加新行

doc.Content.Tables(1).Rows.Add()

doc.Paragraphs.Last.Range.Text = strContext

doc.Paragraphs.Last.Range.Text = "文档创建时间:" & Format(Now,"yyyy-MM-dd HH:mm:ss") '“落款”

doc.Paragraphs.Last.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight

Dim f As Object = doc.SaveFormat

'保存文件

doc.SaveAs("c:/新年第二天.doc")

doc.Close()

docApp.Quit()

End Sub

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值