I needed to export some data in .Csv format from an application made totally for the browser . As usual LotusScript helped me: here are the steps I took:
- create a view with the data you want to export and call it “export”
- create an agent to be invoked by the application that physically performs the export (let’s call it exportCsv)
- in the application I insert a link in this format /folder/app.nsf/esportacsv?openagent that opens in a new window where esportacsv is the name of the agent
Then the agent:
Dim s As New NotesSession Dim questodb As NotesDatabase Dim vec As NotesViewEntryCollection Dim view As NotesView Dim nomevista As String Dim entry As NotesViewEntry Dim nomefile As String Dim strn as string nomevista = "esporta" 'view name nomefile = "esportazione.csv" 'file name Set questodb = s.CurrentDatabase Set view = questodb.GetView(nomevista) Set vec = view.AllEntries Set entry = vec.GetFirstEntry 'HTTP HEADER: Print "Content-Disposition: attachment; filename=" & nomefile Print "Content-Type: application/octet-stream" strn = "" 'columns ForAll c In view.Columns strn = strn & |"| & c.Title & |",| End ForAll 'fields Print strn strn = "" While Not (entry Is Nothing) ForAll cols In entry.ColumnValues cols = |"| & cols & |",| strn = strn & cols End ForAll Print strn strn = "" Set entry = vec.GetNextEntry(entry) Wend
as you can see it essentially does a series of prints but as it initially runs this
Print "Content-Disposition: attachment; filename=" & nomefile
the browser interprets it as a file to be downloaded.
0 Comments