OpenNTF.org - Excel Report Class
    Advanced
   OpenNTF Code Bin
About This Code
Brief Description:
Excel Report Class 
Rating:
Rating: 4.5 , Number of votes: 4 
Contributor:
Christian Gorni 
Category:
Lotusscript, VB 
Type:
OLE/ActiveX 
Document Release:
1.2.0 
Notes Version:
R6.x 
Last Modified:
07 Nov 2005 
OpenNTF Disclaimer

All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.

Code / Description
I wanted to have an Excel reporting class, because i often use Excel for reporting purposes of Lotus Notes. I didn't find any appropriate example on the internet. So I did it myself with


http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-6AVMHV

as inspiration.

Well, somehow I got carried away :-) I think the current state might be of interest to others, so here it is.

Ideas are appreciated!

V1.2.0
---------
QUICK ADDITION: had to disable the destructor, didn't work as intended
- added some comments
- reentered "isWithheader" functionality in view export (somehow that got lost). Check your number of parameters for that function if you already use it !!
- added class destructor

V1.1.0
--------
- basic functionality

Usage / Example
Just use the database. It includes the complete ExcelReport class and two agent examples. As a teaser, the following is all you need to export a view to excel in LotusScript:

...
Set view = ws.CurrentView.View
Set report = New ExcelReport(excelfilepath, False)
Call report.exportNotesView(view, Sheet, OffsetX, OffsetY, isWithHeader, includeIcons, includeColors, includeHidden)
Call report.setVisibility(True)
...

Of course the obvious (getting and setting cells, saving, ...) is also included. Be careful, because error handling is not yet implemented.

Here are the implemented methods:

Sub new (xlFilename As String, isVisible As Boolean)
Sub delete ()
Function save ()
Function saveAs (filename as String)
Function quit ()
Function setCell ( Sheet As Variant , row As Integer , column As Variant , value As String )
Function getCell ( Sheet As Variant , row As Integer , column As Variant ) As String
Function setVisibility (isVisible As Boolean)
Function setCellColor ( Sheet As Variant , row As Integer , column As Variant, innercolor As Variant )
Function setCellFont ( Sheet As Variant , row As Integer , column As Variant, style As Variant, size As Variant, color As Variant )
Function getVersion () As String
Function exportNotesView (view As NotesView, Sheet As Variant, OffsetRow As Integer, OffsetCol As Integer, isWithHeader as Boolean, includeIcons As Boolean, includeColors As Boolean, includeHidden As Boolean)


C.
Code Attachments
 Comments
Posted by Dwight Wilbanks on 04/03/2005 10:47:21 PMVery Nice
Might I suggest allowing for numeric and date values?
Public Function setCell( Sheet As Variant , row As Integer , column As Variant , value As Variant )
If Typename(value) = "STRING" Then
xlApp.Workbooks(1).Worksheets( Sheet ).Cells( row , column ).Value = Chr(39) & value
Else
xlApp.Workbooks(1).Worksheets( Sheet ).Cells( row , column ).Value = value
End If
End Function
With this you can get rid of the cstr in exportNotesView, and it won't interpret phone numbers as a numeric string.
Chr(39) is the single quote with allows you to put a numeric looking value in a text column
I played around with something like this a while back, and found that in some wierd cases the column definitions on the views did not always match up with the column values array on the document. Since in my case the specific views that I wanted to report on did not export well, I went another way.
Im pretty sure that I scrapped it all together (big bit bucket in the sky). But, It did colors, basic fonts and skipped hidden columns.
If your views have anonymous access you can use the HTTP task render the view to tables & excel will read the HTML directly.
Posted by Vince Schuurman on 11/08/2005 02:04:36 PMLooks good, some suggestions...
setVisibility could be extended to allow column hiding
Other functions that I use often:
setCelFormat
setCelFormula
setWorksheetName
and maybe some other functions, just browse through the VB functions :-)
Posted by Christian Gorni on 11/09/2005 02:49:30 AMGood suggestions
... obviously I do not want to recreate the Excel object model :-) I try to implement the "most common uses", so "setWorksheetName" and "setCellFormula" sound good to me.
What do you want to accomplish with setCelFormat
Posted by Mark Teichmann on 11/09/2005 03:08:53 AMautomation error in setCell method
I opened the demo db locally and pressed 'Export this view to Excel'. I get an automation error in the first line of SetCell...
I have some other Excel export routines in use which works the same way and with them I do not get an automation error.
Posted by Ray Weber on 03/12/2007 10:03:42 AMautomation error in new method
When a filename is passed but that xl file is not available and automation error will be created.
However, when in method "New()"
xlApp.Workbooks.Add
is used instead of
xlApp.Workbooks.Add xlFileName
xl has no problem with added that workbook.
Otherwise this is really nice code. Thanks a lot!
 Add your comment!