Hai all,I have a view and in that if i click the “Export” button from the action bar, all the contents must be exported onto a Excel Sheet. I’ve some idea bout this when this is performed in Notes. But mine is a Web Application. Is it possible to export the view in Web? can anyone help me out with the code for this.
Thank you guys.
Subject: Exporitng to Excel Sheet
Here is a code.
Sub Initialize
'Generate Report|report.xls:
'This agent creates a excel file and dumps it directly to the web browser.
'The browser interprets it as a file.
'The script runs line by line, first taking the view column headers, then
'all the data itself. Please make sure you update the view name.
'It is currently ExportView
Dim session As New NotesSession
Dim db As NotesDatabase
Dim v As NotesView
Dim vc As NotesViewEntryCollection
Dim docX, docY As NotesDocument
Dim entry, entryTwo As notesviewentry
Dim col As Integer
Dim lineitem As String
Dim View As String
Dim Query_String As String
Dim Doc As NotesDocument
Dim ViewName As String
Dim Key As String
Dim Index1 As Integer
Dim Index2 As Integer
Dim a As Variant
Set db = session.CurrentDatabase
Set db=session.currentdatabase
Set v=db.getview("SaveatReception")
a=Trim(Format(Date,"dd-mm-yyyy"))
Call v.Refresh
Set vc=v.GetAllEntriesByKey(a, False)
'Print "ViewName = " + ViewName
'Print "Filter = " + Key
'Sets the download to use Excel
Print |Content-Type:application/vnd.ms-excel|
'Triggers the save/open prompt instead of embedding the spreadsheet in the browser
Print |Content-Disposition: Attachment; filename="Report.xls"|
'On Error Goto errorHandler
'ViewName="webreport"
'Set v = db.GetView(View$)
'ViewName ="3"
‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘‘ByVisitingDate View’’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’’
'Call v.refresh
col=1
Print |<Table border>|
lineitem=""
Forall vColumn In v.Columns
If col=1 Then
lineitem=|<th align="center"><FONT SIZE=3 COLOR="0000FF">|+vColumn.Title
Else
lineitem=lineitem+|<th align="center"><FONT SIZE=3 COLOR="0000FF">|+vColumn.Title
End If
col=col+1
End Forall
lineitem=lineitem
Print lineitem
Set entry = vc.GetFirstEntry()
'Set docX=entry.Document
lineitem=""
While Not entry Is Nothing
col=1
Forall cValue In entry.ColumnValues
If Isarray(cValue)=True Then
cValue=Implode(cValue)
End If
If col=1 Then
lineitem=|<tr>|
End If
If cValue="" Then 'blank value still formats the cell
lineitem=lineitem+|<td> </td>|
'Elseif Isdate(cValue) Then 'date format
' lineitem=lineitem+|<TD ALIGN="right" STYLE="vnd.ms-excel.numberformat:dd-m-yyyy">|+cValue+|</td>|
'Elseif Isnumeric(cValue) Then
' If (v.columns(col-1).numberformat=3) Then 'currency format
' lineitem=lineitem+|<td ALIGN="right" STYLE="vnd.ms-excel.numberformat:$#,##0.00">|+cValue+|</td>|
' Else 'other number format
' lineitem=lineitem+|<td ALIGN="right">|+cValue+|</td>|
' End If
Else 'Plain text format
lineitem=lineitem+|<td>|+cValue+|</td>|
End If
col=col+1
End Forall
Print lineitem+|</tr>|
Set entry = vc.GetNextEntry(entry)
'Set docX=entry.Document
Wend
Print |</table>|
Exit Sub
errorHandler:
Print "There has been an error " & Err() & " : " & Error() & " - On Line "+Cstr (Erl) & Chr$(13)
Exit Sub
End Sub
Subject: Page cannot be Displayed 
hai gaurav,i copied this code into an agent and i called this agent form the action button named “Search” in a view. The whole thing is in the Web. But it says “The page cannot be displayed”.
All i want is to export the view contents into a Excel Sheet on Web.
Where would i’ve gone wrong??
Subject: RE: Page cannot be Displayed 
As the code fetch the value on the basis of today’s date. So please customize the code according to your requirement. Also Include in OptionsOption Public
Option Explicit
%INCLUDE “lsconst.lss”
%INCLUDE “lsxbeerr.lss”
In agent properties select “Agent List Selection”.
This will solve your problem.
Subject: Can I ask one question???
Have you worked with HTML based mulitple embedded views in web application? If yes then please help me out. How can I embedded 2 or more HTML based views on the form.
Thanks for help
Subject: RE: Can I ask one question???
I also tried it out… and it wont show two HTML embedded views…i’m keep on trying many things…
if i crack it i’ll let you know…
Subject: Still… Page cannot be Displayed 
Dude,Still the same problem…
i changed the ‘Options’ part and also in the Agent Properties…
But it wont Display the Page…
Subject: RE: Still… Page cannot be Displayed 
Where are you putting the action button? What target have you set in Agent Properties.
Subject: RE: Still… Page cannot be Displayed 
my action button’s in a View named “All Documents”. And in the Agent Properties… I’ve set the Target as “All Documents in the View”… but still it not working… where’d i go wrong??
Subject: RE: Still… Page cannot be Displayed 
Set Target in Agent Properties to “None”.
Subject: the same view loads up again, but no export!
hey,now it doesn’t says Page Cannot be displayed…
bu still once the buton is been clicked, nothing happens…
but i can see that some processing is done…
but in the end nothing happens…
the same view loads up again…
should i change the view name or something…
Subject: RE: the same view loads up again, but no export!
I have already told you that in my code I have accessed the document from view on the today’s date basis. What are the column names of your view.
As I have used in the code :
a=Trim(Format(Date,“dd-mm-yyyy”))
Set vc=v.GetAllEntriesByKey(a, False)
So it fetches document on the today’s date basis. If you want to export all the data from the view then you have to use allentries property in place of getallenteriesbykey.
Subject: same view loads up again, but no export!
you must me knowing the “Discussion Forum” in Lotus Notes notes… (template name : “discsw6.ntf”)in that there’s a View called “All Documents”, which has all the posts…
i’m working on a similar thing… for now keep this template as a reference… but mine is a Web Application… and yes! i’ve changed the ‘GetAllEntriesByKey’ to ‘AllEntries’… and the Agent Target is set to ‘None’ and i’ve done all the other things you told me… but still nothing happens… some processing takes place… but in the end the same View loads up again… hey should i change the View Name somewhere??
the first column is “Date” and there are three columns which are untitled… and after this there’re two final columns called “Topic” and “Author”… now where am i goin wrong???
Subject: RE: same view loads up again, but no export!
In my case it is working fine. I have also created an action button in view and I have given formula @command([toolsrunmacro];“Agentname”);
When I open the view in the browser and click on the action button, it will display a dialog box in which it ask whether you have to save the excel file or just open the excel file. When i open it all the document from view is displayed in excel file.
Can you send me the code which you have changed? So that I can see it.
Subject: RE: same view loads up again, but no export!
the same code dude… except for the getAllEntries… and i’m also using @Command([toolsrunmacro];“xlexport”)… man! how am i gone crack this…
Subject: Exporitng to Excel Sheet
Have you seen Jake Howletts excellent article at codestore.nethttp://www.codestore.net/store.nsf/unid/EPSD-5VBS6Y?OpenDocument
exports to excel via IQY file