1

未処理のドキュメントを使用して、選択したドキュメントのみで実行されるようにしていますが、選択後、ビューで列の値を探してドキュメントを Excel にエクスポートします。以下のコードを使用していますが、正常に機能していますが、最初のドキュメントは常に、Excel シートにエクスポートされた他のすべてのドキュメントの最後に表示されます。エクスポートされたドキュメントがビューのように完全に順番に表示されるように、コードで何ができるかについての考え。

エクスポートに使用した以下のコードを見てください –</p>

Sub Initialize

 'On Error Goto errhandler
 On Error Resume Next
 Dim session As New NotesSession
 Dim db As NotesDatabase
 Dim doccoll As NotesDocumentCollection
 Dim view As NotesView 
 Dim doc As NotesDocument
 Dim otherdoc As NotesDocument

 Set db = session.CurrentDatabase 
 Set view = db.GetView("CRMOpenIssue") 
 Set doccoll=db.UnprocessedDocuments

 Set oExcel = CreateObject ( "Excel.Application" )
 Set oWorkbook = oExcel.Workbooks.Add
 Set oWorkSheet= oWorkbook.Sheets ( 1 )


 oWorkSheet.Cells(1,1).value="Quote# "
 oWorkSheet.Cells(1,2).value="Quote Line#" 
 oWorkSheet.Cells(1,3).value="Customer - fab"
 oWorkSheet.Cells(1,4).value="OppNum"
 oWorkSheet.Cells(1,5).value="OppLine#" 
 oWorkSheet.Cells(1,6).value="Open Issue#"
 oWorkSheet.Cells(1,7).value="Open Issue"
 oWorkSheet.Cells(1,8).value="Category"
 oWorkSheet.Cells(1,9).value="Due date"
 oWorkSheet.Cells(1,10).value="Owner to resolve issue"
 'oWorkSheet.Cells(1,11).value="Owner/PME Verify when closed"
 oExcel.Worksheets(1).Range("A1:J1").Font.Bold = True

 oExcel.columns("A:A").ColumnWidth=15.00
 oExcel.columns("B:B").ColumnWidth=8.00
 oExcel.columns("C:C").ColumnWidth=15.00
 oExcel.columns("D:D").ColumnWidth=10.00
 oExcel.columns("E:E").ColumnWidth=8.00
 oExcel.columns("F:F").ColumnWidth=8.00 
 oExcel.columns("G:G").ColumnWidth=30.00
 oExcel.columns("H:H").ColumnWidth=30.00
 oExcel.columns("I:I").ColumnWidth=15.00
 oExcel.columns("J:J").ColumnWidth=15.00
 'oExcel.columns("K:K").ColumnWidth=30.00

 row% = 1
 offset% = 0
 lastOffset% = 0 

 If doccoll.count >1 Then 'if more than one doc selected then confirm 
  resp = Messagebox("Do you want to export only the " & _
  "selected " & doccoll.count & " documents?", 36, "Selected only?" )
 Else
  Messagebox "Exporting all rows. (To export only selected " & _
  "rows tick those required in the left margin first.)"
 End If  '6= yes 

 oExcel.visible=True
 Dim i As Integer
 If resp=6 Then 'selected documents
  Set doc = doccoll.GetFirstDocument   
  While Not doc Is Nothing
   If resp=6 Then  

    'row% = offset% + 2
    If y="" Then
     row% = row% + 2
    Else 
     row%=row%+y+1
    End If
    col% = 0 'Reset the Columns
    Set otherdoc = view.getnextdocument(doc)
    If otherdoc Is Nothing Then
     Set otherdoc = view.getprevdocument(doc)
     If otherdoc Is Nothing Then
      Print " >1 doc should be selected"
      End
     Else
      Set otherdoc = view.getnextdocument(otherdoc)
     End If
    Else 'got next doc
     Set otherdoc = view.getprevdocument(otherdoc)
    End If        
   End If
   Forall colval In otherdoc.ColumnValues
    col% = col% + 1

    If Isarray(colval) Then
     ''If col%=10 Then   ''''''''
     columnVal=Fulltrim(colval)
     For y = 0 To Ubound(columnVal)
      offset% = row% + y +lastOffset%   
      'offset% = row% + y  
      oWorkSheet.Cells(offset%,col%).value = columnVal(y) 
      'i=offset%
     Next
    Else
     oWorkSheet.Cells(row%, col%).value = colval 
     'offset% = offset% + 1
    End If
    '''' oWorkSheet.Cells(row%, col%).value = colval '''''
    '''''''End If''''''''
   End Forall

   Set doc = doccoll.GetNextDocument(doc)       
  Wend
 End if
4

3 に答える 3

1

私はベン、アレクセイ、ケンの意見に同意しますが、問題の一部は手つかずのままだったと思いColumnValuesますNotesDocumentCollection

  1. `ColumnValues`プロパティが設定されていない`NotesDocument`オブジェクトが含まれています。`ColumnValues`は、`NotesView`オブジェクトを介して取得するドキュメントに対してのみ設定されます。これは、Rupeshがdoc/otherdocの厄介な部分で解決しようとしていることです。
  2. ビューに表示される方法でソートされるとは限りません。

上記は、NotesDatabase.UnprocessedDocumentsまたはを使用して選択したドキュメントを取得するかどうかに関係なく当てはまりますNotesUIView.Documents。どちらも、ビューアクションで使用すると、選択したドキュメントを返します。
私は過去に同様の問題を抱えていました。コードはありませんが、実行可能な解決策を説明しようと思います。

  1. `NotesDatabase.UnprocessedDocuments`または`NotesUIView.Documents`のいずれかを使用して選択したドキュメントを取得します
  2. 選択したドキュメントの`UniversalId`を使用してリストを作成します
  3. ビュー内のすべてのエントリの`ViewEntryCollection`を取得します
  4. `ViewEntryCollection`のすべてのエントリをループします
  5. `ViewEntry`ごとに、`ViewEntry.IsDocument`かどうかを確認します
  6. Trueの場合、`ViewEntry.UniversalId`が以前に作成されたリストの一部であるかどうかを確認します
  7. Trueの場合、`ViewEntry.ColumnValues`をエクスポートします

ViewEntryこれは、ループ内の電流が実際に選択されたドキュメントの1つであるかどうかを確認するための代替アプローチを使用した作業テストです。

Sub Click(Source As Button)
    Dim selectedDc As NotesDocumentCollection
    Dim tempDoc As NotesDocument
    Dim allVec As NotesViewEntryCollection
    Dim tempVe As NotesViewEntry
    Dim thisView As NotesView
    Dim thisDb As NotesDatabase
    Dim session As New NotesSession

    Dim ws As New NotesUIWorkspace
    Dim thisUiView As NotesUIView

    Set thisUiView = ws.CurrentView
    Set selectedDc = thisUiView.Documents

    If (selectedDc.Count = 0) Then
        Messagebox "No selected documents!"
        Exit Sub
    End If

    Set thisDb = session.CurrentDatabase
    Set thisView = thisUiView.View
    Set allVec = thisView.AllEntries

    Set tempVe = allVec.GetFirstEntry
    While Not tempVe Is Nothing

        If (tempVe.IsDocument) Then
            Set tempDoc = selectedDc.GetDocument(thisDb.GetDocumentByUNID(tempVe.UniversalID))
            If Not (tempDoc Is Nothing) Then
                Messagebox Cstr(tempVe.ColumnValues(1))
            End If
        End If

        Set tempVe = allVec.GetNextEntry(tempVe)
    Wend

End Sub

注:これはかなり古い質問ですが、選択したドキュメントからビューに表示される順序でエクスポートするのは難しいため、この回答を投稿します。

于 2011-03-06T23:05:10.237 に答える
0

このセクション全体を削除できると思います:

Set otherdoc = view.getnextdocument(doc)
If otherdoc Is Nothing Then
 Set otherdoc = view.getprevdocument(doc)
 If otherdoc Is Nothing Then
  Print " >1 doc should be selected"
  End
 Else
  Set otherdoc = view.getnextdocument(otherdoc)
 End If
Else 'got next doc
 Set otherdoc = view.getprevdocument(otherdoc)
End If        

終了条件

何をしようとしていたのかわかりませんが、複数のドキュメントが選択されていることをテストしていたようです。これは、doccoll.count プロパティをテストすることで簡単に実行できます。

If doccoll.count <=1 Then  'etc...

次に、Forall ステートメントを変更して、otherdoc ではなく doc で動作するようにします。

Forall colval In doc.ColumnValues ...
于 2010-10-27T14:31:45.450 に答える
0

また、このループの目的が完全にはわかりません。UnprocessedDocuments は単なる NotesDocumentsCollection です。while ループなどで GetFirstDocument/GetNextDocument を使用してナビゲートします。ドキュメントが選択されていないことを示す警告は、ループ内ではなく、最初に来る必要があります。

Set db = session.CurrentDatabase
Set doccoll = db.UnprocessedDocuments
If doccoll.Count = 0 Then
  Print " >1 doc should be selected"
  Exit Sub
End If

その後、Excelの初期化とループを行います

Set doc = doccoll.GetFirstDocument
While Not doc Is Nothing
  ' enter code here'

  Set doc = doccoll.GetNextDocument(doc)
Wend

列については、再確認します。NotesDocument は、常に同じように動作するオブジェクトです。しかし、メモはメモです...私も確認してフィードバックを提供します。

于 2010-10-29T15:24:32.853 に答える