日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

VB.NET 创建WORD文档

發(fā)布時(shí)間:2025/3/20 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 VB.NET 创建WORD文档 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

?? ?1、添加引用->COM->Microsoft Word 11.0 Object Library

?? ?2、Imports Word?

? ''' <summary>''' 創(chuàng)建word文檔''' </summary>''' <remarks></remarks>Public Sub CreateDoc()Dim docApp As New Word.ApplicationDim doc As Word.DocumentDim miss As Object = System.Reflection.Missing.Valuedoc = docApp.Documents.Add(miss, miss, miss, miss)Dim strContext As String = ""'文件內(nèi)容strContext = "你好,我簡單的幸福."'行距docApp.Selection.ParagraphFormat.LineSpacing = 15'頁眉With docApp.ActiveWindow.View.Type = Word.WdViewType.wdOutlineView.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader.ActiveWindow.ActivePane.Selection.InsertAfter("[頁眉內(nèi)容]").Selection.Paragraphs.Alignment = WdParagraphAlignment.wdAlignParagraphRight.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument '跳出頁眉設(shè)置End With'頁尾With docApp.ActiveWindow.View.Type = Word.WdViewType.wdOutlineView.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryFooter.ActiveWindow.ActivePane.Selection.InsertAfter("[頁尾內(nèi)容]").Selection.Paragraphs.Alignment = WdParagraphAlignment.wdAlignParagraphRight.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocumentEnd 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 = 105End With'填充表格內(nèi)容With table.Cell(1, 1).Range.Text = "產(chǎn)品詳細(xì)信息表".Cell(1, 1).Range.Bold = 2 '粗體.Cell(1, 1).Range.Font.Color = WdColor.wdColorBrown'合并單元格.Cell(1, 1).Merge(.Cell(2, 3)) '橫向合并End WithWith docApp.Selection.Cells.VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter '垂直居中.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter '水平居中End WithWith table.Cell(2, 1).Range.Text = "品牌名稱:".Cell(3, 1).Range.Text = "史丹奴"End With'縱向合并單元格table.Cell(3, 3).Select() '選中一行Dim moveUnit As Object = Word.WdUnits.wdLineDim moveCount As Object = 5Dim moveExtend As Object = WdMovementType.wdExtendWith 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 = FalseDim saveWithDoc As Object = TrueDim anchor As Object = doc.Application.Selection.RangeWith doc.Application.ActiveDocument.InlineShapes.AddPicture(strPicPath, linkToFile, saveWithDoc, anchor).InlineShapes(1).Width = 100 '圖片寬度 .InlineShapes(1).Height = 100 '圖片高度End With'設(shè)置圖片為四周環(huán)繞型Dim s As Word.Shapes = doc.Application.ActiveDocument.InlineShapes(1).ConvertToShape()s.WrapFormat.Type = WdWrapType.wdWrapSquare'添加新行doc.Content.Tables(1).Rows.Add()doc.Paragraphs.Last.Range.Text = strContextdoc.Paragraphs.Last.Range.Text = "文檔創(chuàng)建時(shí)間:" & Format(Now, "yyyy-MM-dd HH:mm:ss") '“落款”doc.Paragraphs.Last.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRightDim f As Object = doc.SaveFormat'保存文件doc.SaveAs("c:/新年第二天.doc")doc.Close()docApp.Quit()End Sub?

3 效果預(yù)覽

總結(jié)

以上是生活随笔為你收集整理的VB.NET 创建WORD文档的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。