操纵微软文字处理软件

本文关键字:软件 文字处理 微软 操纵 | 更新日期: 2023-09-27 17:54:55

我目前正在编写这个应用程序来打印和创建一个新的word文档的报告。然而,我遇到了一个绊脚石。当我将数据写入新的Microsoft word文档时,他们是否有办法检查它是否为新页面,例如报告占用了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

操纵微软文字处理软件

你可以每次检查你的word文档的页数,然后创建一个if子句来做一些事情。

你可以数页数:

myPageObject.Count //returns int

每次写入数据时检查是否有新的页面。

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

或者你可以用while子句:

  while(pagecountbefore == myObjectPage.Count){
       //Do Something 
  }

在插入所有行之后,为什么不直接将表的第一行设置为标题行呢objTable.Rows(1)。HeadingFormat = True

if将在每个页面的顶部显示表格的span