xPage Export to Excel using Lotus Script:
Export to Excel using Lotus Script: Yes, export to excel using your lotus script on the xPage , as earlier
we said xPages supports Lotus Script agent ,this is the one of the example.
Here we will see how we can export viewpanel documents to excel using our lotus script.
We are sure that as a lotus notes developer, you have been using this technique for many years to export documents using lotus script, here the same technique we are now applying on xPage.
Yes, the same technique on xPage!
In earlier article we think you have seen export to excel using client side JavaScript. If not, please look at once - here is the link "Export to excel using JavaScript". In this JavaScript export we have used "content type" method to export documents in excel, but it has some drawbacks as this i.e. JavaScript content type technique is not supportive to all browsers. But here, i.e. with Lotus Script we will try to cover all your limitations and will try to provide foolproof export to excel using LotusScript.
So let’s find out the examples.
First we will explain the concepts behind this-
We have added the "view Panel" on xPage and then one "export to excel" button control on the top of the viewPanel.
Now here we need one help from client side JavaScript. So we will add client side JavaScript on the button control to call the Lotus Script agent, we think you are aware of this technique.
Now let’s start with steps-
2. Add below client side JavaScript code on the button control to call
Lotus script agent.
window.open('http://<server_name>/<database_name>/exportToexcel?OpenAgent');
Simple!
haddler:
Print "Error in export to excel Error Line " + Cstr(Erl)+ "& error is "+ Cstr(Error)
Thanks for reading this article, hope you like it, if you have any difficulty please contact us on ‘admin@xpagedomino.com’ or click here to contact us.
Here we will see how we can export viewpanel documents to excel using our lotus script.
We are sure that as a lotus notes developer, you have been using this technique for many years to export documents using lotus script, here the same technique we are now applying on xPage.
Yes, the same technique on xPage!
In earlier article we think you have seen export to excel using client side JavaScript. If not, please look at once - here is the link "Export to excel using JavaScript". In this JavaScript export we have used "content type" method to export documents in excel, but it has some drawbacks as this i.e. JavaScript content type technique is not supportive to all browsers. But here, i.e. with Lotus Script we will try to cover all your limitations and will try to provide foolproof export to excel using LotusScript.
So let’s find out the examples.
First we will explain the concepts behind this-
We have added the "view Panel" on xPage and then one "export to excel" button control on the top of the viewPanel.
Now here we need one help from client side JavaScript. So we will add client side JavaScript on the button control to call the Lotus Script agent, we think you are aware of this technique.
Now let’s start with steps-
1. Add viewPanel & a button
control on the xPage. As shown in below screen.

window.open('http://<server_name>/<database_name>/exportToexcel?OpenAgent');
Simple!

3. Now run below Lotus Script
agent on the xPage.
Sub
Initialize
'Copyright xpagedomino (www.xpagedomino.com)
'Contact admin@xpagedomino.com for any
comments
On Error
Goto haddler
Dim session As New NotesSession '// your notes session
Dim database As NotesDatabase '//
database declaration
Dim view As
NotesView '// view declaration, remember this is the
same view object declaration which we are
referring for xPage viewPanel
Dim doc As
NotesDocument '// document declaration . its the
viewpannle document
Set database=session.currentdatabase
'// database object declaration
Set view = database.GetView(<your
current viewPanel view name>) '// this is
an important line, add a same view name (not viewpannel name) which you
have used on xpage viewpannle control for export functionality
Set doc=view.GetFirstDocument
If Not
doc Is Nothing Then
thead="<th>FirstName </th>"
thead=thead+"<th> LastName
</th>"
thead=thead+"<th> DOB
</th>"
thead=thead+"<th> City
</th>"
thead=thead+"<th> Country
</th>"
' // setting of column name
as header for excel columns
While Not doc Is Nothing
tr=tr+"<tr>"
tr=tr+"<td>"+Cstr(doc.FirstName(0))+"</td>"
tr=tr+"<td>"+Cstr(doc.LastName(0))+"</td>"
tr=tr+"<td>"+Cstr(doc.DOB(0))+"</td>"
tr=tr+"<td>"+Cstr(doc.City(0))+"</td>"
tr=tr+"<td>"+Cstr(doc.Country(0))+"</td>"
tr=tr+"</tr>"
'// Actual values for rows which you want to display as
excel rows
Set doc=view.GetNextDocument(doc)
Wend
table=+"<table border='1'>"+thead+tr+"</table>"
'// create your final table with table head , rows
and data values
End If
Print {Content-Disposition:
Attachment; filename=exporttoexcelLS.xls}
'// define this content type for your
excel file to set name and excel file as attachment for browsers
Print {Content-Type:application/vnd.ms-excel}
'// define this content type to set file type as
excel file
Print table '// finally
open your excel file on browser using "Print table
Exit
Sub
haddler:
Print "Error in export to excel Error Line " + Cstr(Erl)+ "& error is "+ Cstr(Error)
End
Sub
Result -
Screenshot : exported excel file-
Here you can find total 10 rows which are similar
to xPage view panel with border 1 as we have added in script.
We think this is a simplest way to export documents
to excel, you can this code as per the need for project.
Also, there are some other scripts that will also
help to generate the similar export to excel functionality and That can be done
through Server side JavaScript (SSJS), we will show you in the next article
Hers is the link -
Note: we can also customize this lotus script export to excel function on
selected documents also. I.e. we can export those documents which we have
selected using check box. For this you can add checkbox for your first column
using xpage viewpanel property (no code required to add checkbox) and this we
will show in other article. “Export to excel using lotus script on selected
document”
Thanks for reading this article, hope you like it, if you have any difficulty please contact us on ‘admin@xpagedomino.com’ or click here to contact us.
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a comment