17.07.2010

Quick Tip: Simple Excel export from Domino Web applications

>>Author:  Thomas Bahn
>>Ort:     Schwentinental (Kiel)
        
URL: http://www.assono.de/blog/d6plinks/Quick-Tipp-Simple-Excel-Export-from-Domino-Web-Applications

Category: Quick-Tipp, Lotus Notes, Entwicklung

At times you want to export documents from a Domino Web application in order to work with the data in a spreadsheet like Microsoft Excel, to prepare, process and visualize the information.

A simple, but flexible way is to write an LotusScript agent in the Web app, which "prints" a HTML table:

Sub Initialize()
        Print |Content-Type:application/vnd.ms-excel|
        Print |Content-Disposition: Attachment; filename="exportToExcel.xls"|
        Print ||
        Print |<table>|
        Print |<tr><th>Tabelle</th><th>1. Spalte</th><th>2. Spalte</th><th>3. Spalte</th></tr>|
        Print |<tr><td>1. Zeile</td><td>1</td><td> 2</td><td> 3</td></tr>|
        Print |<tr><td>2. Zeile</td><td>2</td><td> 4</td><td> 7</td></tr>|
        Print |<tr><td>3. Zeile</td><td>3</td><td> 7</td><td>14</td></tr>|
        Print |<tr><td>4. Zeile</td><td>4</td><td>11</td><td>25</td></tr>|
        Print |</table>|
End Sub


The "trick" is to start with the Content-Type "application/vnd.ms-excel".

Instead of just printingt static data (like in the example), the agent would calculate the table using a view or search and iterating through the documents.

Comments

#1 Can a similar approach be taken to export into a .pdf? Gravatar Image
#2 I don't think so. At least, not as easy. You could create pdf files on the fly (we did so using OpenOffice.org, iText and FOP in different projects), but AFAIK the Adobe Reader doesn't read HTML (independent of the file type or extension) and displays it as PDF... Gravatar Image
#3 Is there any way to export excel to XLSX file format like this in web. I tried using "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" content type but still it gives a warning message when opening the excel. Gravatar Image
#4 This is not ! an export in xls format, but in a content type, Excel declares to handle and understands. Thus, this HTML page is opened = imported by Excel, even Excel 2010, and can be saved in any format you like.

I think, there are some libraries out there, which can create XLSX files programatically. But I don't know nor use them.

Why do you want to create XLSX files?
Gravatar Image

Post A Comment

Comments

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::lips::rolleyes:;-)

Tags

Deutsche RSS-Feeds (German)

Custom Button Custom Button

English RSS feeds

Custom Button Custom Button