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

虽然我同意 Ben、Alexey 和 Ken 的观点,但我认为问题的一部分没有被触及——ColumnValuesNotesDocumentCollection你有以下情况时,你如何导出:

  1. 包含 `NotesDocument` 对象,其中 `ColumnValues` 属性未设置。`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循环中的电流是否实际上是所选文档之一:

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

我也不完全理解这个循环的用途。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 回答
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 语句更改为使用 doc 而不是 otherdoc:

Forall colval In doc.ColumnValues ...
于 2010-10-27T14:31:45.450 回答