QTP实现向word里写入表格

2012-05-16  付民 

原创:转载请注明出处

测试脚本:
EditWord "F:\test.docx"
Function EditWord(filepath)
   Set oWordApp = CreateObject("Word.Application")
   oWordApp.Visible = True
   Set oWordDoc = oWordApp.Documents.Open(filepath)
   oWordDoc.Range.Select
   Set oWordSel = oWordApp.Selection
  With oWordSel
  Set oNewTable = .Tables.Add(.range,5,3)
  oNewTable.Range.Font.Size = 8
  i = 1
  oNewTable.Cell(i, 1).Range.Text = "i"
oNewTable.Cell(i, 2).Range.Text = "i * 2"
oNewTable.Cell(i, 3).Range.Text = "i * 3"

For i = 2 To 5
oNewTable.Cell(i, 1).Range.Text = i - 1
oNewTable.Cell(i, 2).Range.Text = (i - 1)*2
oNewTable.Cell(i, 3).Range.Text = (i - 1)*3
Next

oNewTable.Rows.Add
i = oNewTable.Rows.Count
oNewTable.Cell(i, 1).Range.Text = i - 1
oNewTable.Cell(i, 2).Range.Text = (i - 1)*2
oNewTable.Cell(i, 3).Range.Text = (i - 1)*3
  End With
End Function

实现结果:


444°/4430 人阅读/1 条评论 发表评论

关敏  2012-06-12

分享了


登录 后发表评论