-1

我目前正在编写这个应用程序来打印和创建一个新的 Word 文档的报告。然而,我遇到了一个绊脚石。当我将数据写入这个新的 Microsoft word doc 以检查它是否是一个新页面时,他们有什么办法吗?例如,报告占用 10 页,他们是一种检查应用程序何时开始在新页面上写入的方法吗?


代码:

Dim objWord 
As Word.Application
Dim objDoc As Word.Document
Dim objTable As Word.Table
Dim r As Integer, c As Integer
Dim pages1 As Pages
Dim pagecountbefore As Integer

objWord = CreateObject("Word.Application")
objWord.Visible = True
objDoc = objWord.Documents.Add

pagecountbefore = pages1.Count

objTable = objDoc.Tables.Add(objDoc.Bookmarks.Item("\endofdoc").Range, 3, 5)
objTable.Range.ParagraphFormat.SpaceAfter = 6
For r = 1 To 1000
    For c = 1 To 5
         If r = 1 Then
            Select Case c
                Case "1"
                    objTable.Cell(r, c).Range.Text = "PCI DSS Requirements "
                Case "2"
                    objTable.Cell(r, c).Range.Text = "Testing Procedures "
                Case "3"
                    objTable.Cell(r, c).Range.Text = "In Place"
                Case "4"
                    objTable.Cell(r, c).Range.Text = "Not in Place"
                Case "5"
                    objTable.Cell(r, c).Range.Text = "Target Date/ Comments"
            End Select
        Else
            If pagecountbefore<pages1.Count Then
                pagecountbefore = pages1.Count
                Select Case c
                    Case "1"
                        objTable.Cell(r, c).Range.Text = "PCI DSS Requirements "
                    Case "2"
                        objTable.Cell(r, c).Range.Text = "Testing Procedures "
                    Case "3"
                        objTable.Cell(r, c).Range.Text = "In Place"
                    Case "4"
                        objTable.Cell(r, c).Range.Text = "Not in Place"
                    Case "5"
                        objTable.Cell(r, c).Range.Text = "Target Date/Comments"
                End Select
            Else
              'print resultrs from database
            End If
        End If
    Next
Next
4

2 回答 2

0

您可以每次检查 Word 文档的页数,然后创建一个 if 子句来执行某些操作。

您可以使用以下方法计算页面:

myPageObject.Count //returns int

然后在每次写入数据时检查新页面。

//Writing Data 
if(pagecountbefore < myObjectPage.Count){
    //Do Something 
}

或者您可以使用 while 子句来做到这一点:

  while(pagecountbefore == myObjectPage.Count){
       //Do Something 
  }
于 2013-01-22T05:59:39.117 回答
0

为什么不插入所有行后将表格的第一行设置为标题行,只需说 objTable.Rows(1).HeadingFormat = True

如果将显示在表格跨越的每一页的顶部

于 2016-09-09T14:22:15.810 回答