Skip to content

Instantly share code, notes, and snippets.

@toronya
Last active December 11, 2015 12:38
Show Gist options
  • Save toronya/4602183 to your computer and use it in GitHub Desktop.
Save toronya/4602183 to your computer and use it in GitHub Desktop.
Lotus Notes View Download as csv. Lotus Notes Agent Script.
Option Declare
'#-------------------------------------------------------#
'# http://example.com/test.nsf/exportcsv?openagent #=> CSV File Download
'#-------------------------------------------------------#
Sub Initialize
'====================
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase
Dim view As NotesView
Dim view_name as String
view_name = "CSV" '# SET UP VIEW NAME
Set view = db.GetView(view_name)
Dim ve As NotesViewEntryCollection
Set ve = view.AllEntries
Dim entry As NotesViewEntry
Set entry = ve.GetFirstEntry
Dim strFname As String
strFname = view_name & "_" & Format( Now(), "yyyy_mmdd_hhnnss" ) & ".csv" '# SET UP DOWNLOAD CSV FILE NAME
'# HTTP HEADER
'# to pop up web browser download dialog.
Print "Content-Disposition: attachment; filename=" & strFname
Print "Content-Type: application/octet-stream"
'# Print CSV data
Dim strn
strn = ""
'# CSV HEADER
Forall c In view.Columns
strn = strn & |"| & c.Title & |",|
End Forall
'# CSV BODY
Print strn
strn = ""
While Not (entry Is Nothing)
Forall cols In entry.ColumnValues
cols = |"| & cols & |",|
strn = strn & cols
End Forall
'# Print CSV BODY
Print strn
strn = ""
Set entry = ve.GetNextEntry(entry)
Wend
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment