查看: 590|回复: 7
|
VBScript Export去Excel后分开cells的问题
[复制链接]
|
|
大家好,小弟是个vbscript白痴。
我在网上找到了一个vbscript,能够把电脑里所安装的软件全部export去excel里。
可是export后全部都是在同一个column,有谁能够教我改这个script怎样把它分开啊?
比如Computer Name是column A,Application是column B,Vendor是column C,Version是column D。
谢谢各位高手。
'*******************************************************************************
' software.vbs
' Create a list of software installed on one or more
' machines in TSV format.
'
' Usage: cscript.exe software.vbs [/path:<path>] [machine names]
'
' If <path> is given, the script will attempt to store logs
' in that location. It is treated as a relative path and must
' end in a backslash.
'*******************************************************************************
' Define a bunch of constants VBScript should define for us but doesn't
Const ForReading = 1, ForWriting = 2, ForAppending = 8
' Get shell and network
Set objShell = CreateObject("Wscript.Shell"
Set objNet = CreateObject("WScript.Network"
Set objArgs = WScript.Arguments
' Array to hold computer names
Dim arrComputers()
' Get attributes, if we got command line arguments, use those
' as the hostnames. Otherwise use the local machine name.
If objArgs.Unnamed.Length > 0 Then
Dim i
i = 0
While i < objArgs.Unnamed.Length
ReDim Preserve arrComputers(i)
arrComputers(i) = objArgs.Unnamed.Item(i)
i = i + 1
Wend
Else
ReDim arrComputers(0)
arrComputers(0) = objNet.ComputerName
End If
' Get named arguments if they were passed
Dim strLogPath
If objArgs.Named.Length > 0 Then
strLogPath = objArgs.Named.Item("path"
Else
strLogPath = ""
End If
' Create a FSO to write the output to a text file
Set objFSO = CreateObject("Scripting.FileSystemObject"
' Get a list of software from each machine and format it as TSV.
For Each strComputer In arrComputers
' Put some error handling in here, if we can't contact the computer
' then we log the failure and move on.
On Error Resume Next
' Get the list of installed software
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2"
Set colItems = objWMIService.ExecQuery("Select * FROM Win32_Product",,48)
If Err.Number <> 0 Then
' An error occurred trying to contact the machine, skip this computer
' and log the error so it can be noted and investigated.
objShell.LogEvent 1, "software.vbs: Could not contact computer: " & _
strComputer
On Error Goto 0
Else
' No error contacting the machine so write the log file.
On Error Goto 0
' Create and/or open the log file
Dim currentDate
currentDate = Date
Dim currentTime
currentTime = Time
Set objLogFile = objFSO.OpenTextFile(_
strLogPath & _
strComputer & _
"_" & _
Year(currentDate) & _
"-" & _
Month(currentDate) & _
"-" & _
Day(currentDate) & _
"-" & _
Hour(currentTime) & _
"-" & _
Minute(currentTime) & _
"-" & _
Second(currentTime) & _
"_" & _
"log.csv", ForWriting, True)
' Start the tsv
objLogFile.WriteLine _
"computer" & _
vbTab & _
"application" & _
vbTab & _
"vendor" & _
vbTab & _
"version"
' Build the tsv
For Each objItem In colItems
objLogFile.WriteLine _
strComputer & vbTab & _
objItem.Name & vbTab & _
objItem.Vendor & vbTab & _
objItem.Version
Next
' Close the log file
objLogFile.Close
End If
Next
WScript.Echo "Finished: software.vbs has finished. Check event log for errors."
WScript.Quit(0)
|
|
|
|
|
|
|
|
发表于 13-1-2017 01:15 PM
|
显示全部楼层
可以先看你export的file吗?有可能可以用excel command就做到。 |
|
|
|
|
|
|
|
楼主 |
发表于 16-1-2017 12:02 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 16-1-2017 02:16 PM
|
显示全部楼层
應該沒問題.
你用excel開csv時,可能要用tab as a separator.
祝順利
|
|
|
|
|
|
|
|
楼主 |
发表于 17-1-2017 01:52 PM
|
显示全部楼层
什么意思?可以解释详细点吗?
|
|
|
|
|
|
|
|
发表于 17-1-2017 02:02 PM
|
显示全部楼层
excel 2007 - Data > from textdelimited > tab > finish
|
评分
-
查看全部评分
|
|
|
|
|
|
|
楼主 |
发表于 17-1-2017 05:00 PM
|
显示全部楼层
原来我还是个Excel白痴。
谢谢你啦~
|
|
|
|
|
|
|
|
发表于 18-1-2017 05:54 AM
|
显示全部楼层
不客氣
術業有專精,改天也有會向你請教的時候.
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|