dongxiaoling1029

导航

资料自用~

相关Class:
NotesRichTextItem
NotesRichTextNavigator
NotesRichTextTable
NotesRichTextRange
NotesRichTextStyle

代码如下:

Sub CreateReport(sealDoc As NotesDocument)
   
    On Error Goto ErrorHandler
   
    Dim keys(1 To 3) As String
    Dim doc As NotesDocument
    Dim values As Variant
   
    Dim reportDoc As NotesDocument
    Dim item As NotesItem
    Dim body As NotesRichTextItem
    Dim rtnav As NotesRichTextNavigator
    Dim rttable As NotesRichTextTable
    Dim rtr As NotesRichTextRange
    Dim rts As NotesRichTextStyle
    Dim columnCount As Integer
    Dim rowCount As Integer
    Dim rowCountAfter As Integer
   
    Dim i As Integer, j As Integer
    Dim count_read As Integer   

    '新規レポート文書作成
    Set dt = New NotesDateTime("")
    Call dt.SetNow()
    reportYear = Year(dt.LSLocalTime)
    reportMonth = Month(dt.LSLocalTime)
    Set reportDoc = mainDb.CreateDocument
    Call reportDoc.ReplaceItemValue("Form", "Report")
    Call reportDoc.ReplaceItemValue("Title", sealDoc.GetItemValue("Title"))
    Call reportDoc.ReplaceItemValue("Holder", sealDoc.GetItemValue("Holder"))
    Call reportDoc.ReplaceItemValue("HolderName", sealDoc.GetItemValue("HolderName"))
    Call reportDoc.ReplaceItemValue("DeptName", sealDoc.GetItemValue("DeptName"))
    Call reportDoc.ReplaceItemValue("Location", sealDoc.GetItemValue("Location"))
    Call reportDoc.ReplaceItemValue("Sector", sealDoc.GetItemValue("Sector"))
    Call reportDoc.ReplaceItemValue("ID", sealDoc.GetItemValue("ID"))
    Call reportDoc.ReplaceItemValue("ReportMonth", Datenumber(reportYear, reportMonth, 1))

    'フォーマットをコピー
    Set body = reportDoc.CreateRichTextItem("Body")
    Call body.AppendRTItem(formatItem)
   
    '表の最後のセルまで移動
    Set rtnav = body.CreateNavigator
    Call rtnav.FindFirstElement(RTELEM_TYPE_TABLE)
    Set rttable = rtnav.GetElement
    columnCount = rttable.ColumnCount
    rowCount = rttable.RowCount
    Call rtnav.FindLastElement(RTELEM_TYPE_TABLECELL)
   
    '最後のセルと同じスタイルに設定
    Set rtr = body.CreateRange()
    Call rtr.SetBegin(rtnav)
    Set rts = rtr.Style
    Call body.BeginInsert(rtnav, True)
    Call body.AppendStyle(rts)
    Call body.EndInsert()
   
    'レポート作成用 申請書ビュー取得
    keys(1) = sealId
    keys(2) = Format$(reportYear, "0000")
    keys(3) = Format$(reportMonth, "00")
    Set doc = requestView.GetDocumentByKey(keys, True)
   
    Do While Not doc Is Nothing
        count_read = count_read + 1
       
        '表に行を追加
        Call rttable.AddRow(1)
        'ビューの 、offsetの列から、列値を順に書き出す
        For i = offset To Ubound(doc.ColumnValues)
            '表の列数を超えたら、それ以上ビュー列があっても書き出さない
            If i >= offset + columnCount Then
                Exit For
            End If           
            Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
            Call body.BeginInsert(rtnav)
            values = doc.ColumnValues(i)
            If Isarray(values) Then
                For j = Lbound(values) To Ubound(values)
                    Call body.AppendText(Cstr(values(j)))
                    If j < Ubound(values) Then
                        Call body.AddNewline(1)
                    End If
                Next
            Else
                Call body.AppendText(Cstr(values))
            End If
            Call body.EndInsert           
        Next
       
        Set doc = requestView.GetNextDocument(doc)
    Loop
   
    '処理件数書き出し
    Call reportDoc.ReplaceItemValue("ReportCount", count_read)

    'レポート文書保存
    Call reportDoc.Save(True, False)

End Sub

posted on 2011-06-13 21:49  dongxiaoling1029  阅读(163)  评论(0编辑  收藏  举报