扫描多个word文档以创建表格
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了扫描多个word文档以创建表格相关的知识,希望对你有一定的参考价值。
另一个部门在我们拥有的一些服务器上运行安全扫描。结果他们向我发送了几十个word文档(每个服务器一个),其中列出了该服务器的所有安全问题以及有关漏洞的一些数据。我问是否有可能只获得表中的服务器,风险级别和风险类型,这样我就可以确定常见问题并首先关注关键问题。这个部门现在对我保持沉默。
有没有人有一种方法可以搜索单个或多个单词文档,以便将实例输出到新表中?任何指导都会有用,因为我已经通过“风险:”系列出现了100多个这样的文件。
例如,我有“Old Oracle server.doc”,其中一个页面上有以下内容:
--------------------------------------------------------------------
Oracle Database Unsupported Version Detection
--------------------------------------------------------------------
Risk: Critical
我想要一个csv或表格说:
|SERVER |Issue | Level|
|Old Oracle server| Oracle Database Unsupported Version| Critical|
|Old Oracle server| SSL Weak Cipher Suites Supported| Medium|
答案
由于您需要Word表格,因此可以使用以下行编码的Word宏来执行此操作:
Sub GetServerData()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document, strTxt As String
strDocNm = ActiveDocument.FullName: strTxt = "Server" & vbTab & "Issue" & vbTab & "Level" & vbCr
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
If strFolder & "\" & strFile <> strDocNm Then
Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
With wdDoc
With .Range.Find
.ClearFormatting
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchWildcards = True
.Text = "[^13^l]{2,}"
.Replacement.Text = "^p"
.Execute Replace:=wdReplaceAll
.Text = "[-]@[^13^l]([!^13^l]@)[^13^l]*Risk: ([!^13^l]@)[^13^l]"
.Replacement.Text = Split(.Name, ".doc")(0) & "^t\1^t\2^p"
.Execute Replace:=wdReplaceAll
End With
If .Characters.First Like "[" & vbCr & Chr(11) & "]" Then .Characters.First.Delete
If .Characters.Last.Previous Like "[" & vbCr & Chr(11) & "]" Then .Characters.Last.Previous.Delete
strTxt = strTxt & .Range.Text
.Close SaveChanges:=False
End With
End If
strFile = Dir()
Wend
With ActiveDocument.Range
.Text = strTxt
.ConvertToTable Separator:=vbTab, NumColumns:=3
.Tables(1).Rows(1).HeadingFormat = True
.Tables(1).Rows(1).Range.Font.Bold = True
End With
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
以上是关于扫描多个word文档以创建表格的主要内容,如果未能解决你的问题,请参考以下文章