2016-05-23 45 views
0

我使用以下站點作爲將Lotus Notes數據庫表單導出到csv文件的指南。LotusScript - 除部分字段外的導出表單

http://searchdomino.techtarget.com/tip/How-to-export-data-from-a-Lotus-Notes-database-to-a-CSV-file

Sub Initialize 

    Dim session As New NotesSession 
    Dim db As NotesDatabase 
    Dim fileName As String 
    Dim fileNum As Integer 
    Dim headerstring As String 
    Dim values As String 
    Dim selection As String 
    Dim collection As NotesDocumentCollection 
    Dim doc As notesdocument 

    On Error Resume Next 

    Set db = session.CurrentDatabase 

    Forall form In db.Forms 
     If Isempty(form.Fields) Then 
      Messagebox form.Name & " has no fields" 
     Else 
'Specify what form you want to export   
      If form.Name = "Server Information" Then    
       fieldCount = 0 
       msgString = "" 
       fileNum% = Freefile() 
       fileName$ = "c:\temp\LOTUS_EXPORT\" & form.Name & ".csv" 
       Open FileName$ For Output As fileNum% 

       Forall field In form.Fields 
        msgString = msgString & Chr(10) & _ 
        "" & field 
        fieldCount = fieldCount + 1 
        headerstring=headerstring & |"| &field &|",| 
       End Forall 

       Write #fileNum%, |",| & headerstring & |"| 
       headerstring="" 
      Else 
      End If 


     End If 



     selection = |Form="| & form.Name & |"| 
     Set collection=db.Search(selection, Nothing, 0) 

     For x = 1 To collection.count 
      Set doc =collection.GetNthDocument(x) 
      values="" 
      Forall formfield In form.Fields 
        Forall formfield.value != 'AdditionalDocumentation' 
       newvalue=doc.GetItemValue(formfield) 
       values=values & |"| & newvalue(0) & |",| 
      End Forall 
      End Forall 

      Write #fileNum%, |",| & values &|"| 
      values="" 
     Next 

'now check aliases 
     If Isempty(form.Aliases) Then 
'Messagebox form.Name & " has no aliases" 
     Else 
      Forall aliaz In form.Aliases 
       If aliaz = form.Name Then 
        Goto NextAliaz 'alias is same as form name 
       End If 
       selection = |Form="| & aliaz & |"| 
       Set collection=db.Search(selection, Nothing, 0) 

       For x = 1 To collection.count 
        Set doc =collection.GetNthDocument(x) 
        values="" 
        Forall formfield In form.Fields 
         newvalue=doc.GetItemValue(formfield) 
         values=values & |"| & newvalue(0) & |",| 
        End Forall 

        Write #fileNum%, |",| & values &|"| 
        values="" 
NextAliaz: 
       Next 
      End Forall 
     End If 

     Close fileNum% 
    End Forall 

End Sub 

而且,任何容易,我想指定我要導出或導出整個表格,除了一組特定字段的字段。

+0

告訴我們你試過的是什麼,當你嘗試過時發生了什麼。 –

回答

1

另一種方式做克努特·赫爾曼建議在他的回答是創建要導出的字段列表,然後在的ForAll循環您測試,如果eaxch場是名單中的一員:

Dim exportField List As String 

exportField("FieldOne") = "FieldOne" 
exportField("FieldTwo") = "FieldTwo" 
exportField("FieldFive") = "FieldFive" 

,循環:

ForAll formfield In form.Fields 
    If IsElement(exportField(formfield)) Then 
     newvalue=doc.GetItemValue(formfield) 
     values=values & |"| & CStr(newvalue(0)) & |",| 
    End If  
End ForAll 

還有一個原因,我使用的字符串列表。您可以放置​​特殊的格式化命令,或指示數據類型,而不是將字段名稱放在那裏。然後在循環中,您使用相應格式化CSV輸出:

Dim exportField List As String 

exportField("FieldOne") = "T" '*** Text 
exportField("FieldTwo") = "DT" '*** Date and Time 
exportField("FieldFive") = "N" '*** Numeric 
exportField("FieldSix") = "D" '*** Date only 

然後你只需檢查值和正確格式化輸出。

0

form.Fields返回名稱所有字段。測試這個字段名,以排除一些吧:

... 
ForAll formfield In form.Fields 
    If formfield <> "AdditionalDocumentation" And formfield <> "AnotherFieldName" Then 
     newvalue=doc.GetItemValue(formfield) 
     values=values & |"| & CStr(newvalue(0)) & |",| 
    End If  
End ForAll 
相關問題