网络编程 
首页 > 网络编程 > 浏览文章

Add a Formatted Table to a Word Document

(编辑:jimmy 日期: 2025/9/19 浏览:3 次 )
Demonstration script that retrieves service data from a computer and 
then displays that data in a formatted table in Microsoft Word. 
复制代码 代码如下:
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Add()

Set objRange = objDoc.Range()
objDoc.Tables.Add objRange,1,3
Set objTable = objDoc.Tables(1)

x=1

strComputer = "."
Set objWMIService = _
    GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Service")

For Each objItem in colItems
    If x > 1 Then
        objTable.Rows.Add()
    End If
    objTable.Cell(x, 1).Range.Font.Bold = True
    objTable.Cell(x, 1).Range.Text = objItem.Name
    objTable.Cell(x, 2).Range.text = objItem.DisplayName
    objTable.Cell(x, 3).Range.text = objItem.State
    x = x + 1
Next




上一篇:Add a Picture to a Microsoft Word Document
下一篇:一个漂亮的下拉列表,去掉了灰色倒三角按钮
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 网站地图 SiteMap