1

Тема: Отчет с вида с сортировкой результата. Сортировка коллекции документов

Данная кнопка формирует отчет в Эксель для выбранных документов на LotusScript, Коллекция документов отсортировывается по выбранному в коде полю, в данном слкучае - это регномер.

Sub Click(Source As Button)
    On Error Goto ErrH
    Dim session As New NotesSession
    Dim ws As New NotesUIWorkspace
    Dim db As NotesDatabase, strukdb As NotesDatabase
    Dim view As NotesView, uiview As NotesUIView    
    Dim strukdoc As NotesDocument, curdoc As notesdocument, doc As NotesDocument
    Dim EObj  As Variant
    Dim xlsheet As Variant
    Dim xlColumn As String    
    Dim  n As Integer, i As Integer
    Dim item As NotesItem
    Dim who As String
    
    Set db=session.CurrentDatabase
    Dim collection As NotesDocumentCollection
    
    
    Set view = db.GetView("PrikazOtch")
'    Dim numDocs As Integer
    
    Set collection=db.UnprocessedDocuments 'получаем коллекцию выбранных доков(могут быть и ответные и главные)
    If collection Is Nothing Then Exit Sub
    
    Set EObj = CreateObject("Excel.Application")
    Call EObj.Workbooks.Add
    Set xlsheet = EObj.Workbooks(1).Worksheets(1)   
    EObj.visible = True
    
    xlsheet.Cells(1,1)= "Дата"
    xlsheet.Cells(1,2)= "Рег.Номер"
    xlsheet.Cells(1,3)="Заголовок"
    xlsheet.Cells(1,4)="Кем подписан"  
    xlsheet.Cells(1,5)="Отв.за контроль"
    xlsheet.Cells(1,6)="Срок"
    xlsheet.Cells(1,7)="Чем исполнен"
    xlsheet.Cells(1,8)="К-во экз."
    xlsheet.Cells(1,9)="Копии"
    
    n=2
    
    Dim mas() As notesdocument
    Print "collection.count  " collection.count 
    Redim mas(collection.count - 1)
    Set doc = collection.GetFirstDocument
    i=0
    While Not doc Is Nothing   ' заполняем массив mas(i) доками с коллекции
        Set mas(i) = doc
        Set doc = collection.getnextdocument(doc)
        i=i+1
    Wend
    
    For i = 0 To Ubound(mas)-1
        For j = i To Ubound(mas)
            Print   "i="  i     "   j="   j   
            If Int( Strrightback(mas(i).Getitemvalue("fullregnom")(0),"/") ) >  Int( Strrightback(mas(j).Getitemvalue("fullregnom")(0),"/") )  Then
                Print "рокировка"  mas(i).fullregnom(0)  "   -   "  mas(j).fullregnom(0)
                Set tmpval = mas(i)
                Set mas(i) = mas(j)
                Set mas(j) = tmpval
            End If
        Next
    Next
    
    
    For i = 0 To Ubound(mas)-1
        Set curdoc=mas(i)
        
        Print curdoc.fullregnom(0)
        xlsheet.Cells(n,1)=   Left(  Cstr( curdoc.datereg(0)) , 10)
        xlsheet.Cells(n,2).NumberFormat="@"
        xlsheet.Cells(n,2)= Cstr (curdoc.fullregnom(0))
        xlsheet.Cells(n,3)= curdoc.header(0)
        xlsheet.Cells(n,4)=  curdoc.signname(0)
        
        who=""
        Set item = curdoc.GetFirstItem( "whokontrol" )
        If Not item Is Nothing Then
            Forall v In item.Values
                who = who + v + "; "
            End Forall
        End If
        xlsheet.Cells(n,5)= who
        
        xlsheet.Cells(n,6)= curdoc.expir_date(0)
        xlsheet.Cells(n,7)= curdoc.executed(0)
        xlsheet.Cells(n,8)= curdoc.ekz(0)
        xlsheet.Cells(n,9)= curdoc.n_kop(0)
        
        n=n+1
    Next
    
    Exit Sub
ErrH:
    Print "Ошибка: " & Error(Err) & " в строке " & Erl
End Sub

Поделиться