WORD文档中的表格:自定义方式的批处理,增删行列和内容
WORD文檔中的表格:自定義方式的批處理,增刪行列和內(nèi)容;
大家有沒有遇到需要處理WORD文檔中的表格,表格多,需要大量的重復(fù)性工作;
office提供了宏錄制方式,可以編輯風(fēng)格,內(nèi)容,但是針對增刪表格卻不好處理,沒關(guān)系,WORD還支持VB語言的定制處理,可以針對每一個對象的處理,當(dāng)然也可以批量處理。
開發(fā)工具---> Visual Basic :
用戶窗體--->模塊
示例代碼如下,可參考:
Option Explicit
Sub addd()
Dim tbl As Table
Application.ScreenUpdating = False
For Each tbl In ActiveDocument.Tables
?'為了過濾掉可能不是測試用例的表格
?If tbl.Rows.Count >= 8 And tbl.Columns.Count = 1 Then
? '添加3行,在首列前添加1列
? 'tbl.Rows.Add BeforeRow:=tbl.Rows(5)
? 'tbl.Rows.Add BeforeRow:=tbl.Rows(5)
? 'tbl.Rows.Add BeforeRow:=tbl.Rows(5)
? 'tbl.Columns.Add BeforeColumn:=tbl.Columns(1)
? tbl.AutoFitBehavior (wdAutoFitContent)
End If
?'If tbl.Rows.Count >= 8 And tbl.Columns.Count = 2 Then
? '添加3行,在首列前添加1列
?' tbl.Rows.Add BeforeRow:=tbl.Rows(5)
?' tbl.Rows.Add BeforeRow:=tbl.Rows(5)
'? tbl.Rows.Add BeforeRow:=tbl.Rows(5)
? 'tbl.Columns.Add BeforeColumn:=tbl.Columns(1)
'? tbl.AutoFitBehavior (wdAutoFitContent)
'End If
? '設(shè)置首列固定寬度
? tbl.Columns(1).Width = 60
? '設(shè)置首列對應(yīng)的內(nèi)容
? tbl.Cell(Row:=1, Column:=1).Range.Text = "用例編號"
? tbl.Cell(Row:=2, Column:=1).Range.Text = "用例名稱"
? tbl.Cell(Row:=3, Column:=1).Range.Text = "測試目的"
? tbl.Cell(Row:=4, Column:=1).Range.Text = "預(yù)置條件"
? tbl.Cell(Row:=5, Column:=1).Range.Text = "測試點"
? tbl.Cell(Row:=6, Column:=1).Range.Text = "樣本點"
? tbl.Cell(Row:=7, Column:=1).Range.Text = "測試環(huán)境"
? tbl.Cell(Row:=8, Column:=1).Range.Text = "測試步驟"
? tbl.Cell(Row:=9, Column:=1).Range.Text = "預(yù)期結(jié)果"
? tbl.Cell(Row:=10, Column:=1).Range.Text = "測試結(jié)果"
? tbl.Cell(Row:=10, Column:=2).Range.Text = ""
? tbl.Cell(Row:=11, Column:=1).Range.Text = "測試結(jié)論"
? tbl.Cell(Row:=11, Column:=2).Range.Text = "通過[? ] 未通過[? ] 未測[? ]"
? tbl.Cell(Row:=12, Column:=1).Range.Text = "備注"
??
Next
Application.ScreenUpdating = True
End Sub
總結(jié)
以上是生活随笔為你收集整理的WORD文档中的表格:自定义方式的批处理,增删行列和内容的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 比较常用的10个markdown标签
- 下一篇: list(map(lambda x:x[