Export View to Excel

Print the contents of any Notes view to Excel with the click of a button. The code is totally dynamic in R5, in R4 you have to make one small change.
 Sub Click(Source As Button)
	Dim WS As notesuiworkspace
	Dim UiView As notesuiview
	Dim ViewString As String
	Dim session As NotesSession
	Dim db As NotesDatabase 
	Dim v As NotesView
	Dim docX As NotesDocument
	Dim col As Integer
	Dim row As Double
	Dim xl As Variant
	Dim xlWbk As Variant
	Dim pagename As String
	
	Set WS = New notesuiworkspace
	Set session = New notessession
	Set db=session.CurrentDatabase
	
	Print "Please Be Patient as the Excel Spreadsheet is being created..."
	
' Get dynamic view name, R5 only
' Take this part out if using in R4, you have to hard-code the name of the view in ViewString
	Set UiView=WS.currentview
	ViewString=UiView.viewname
	
	Set v=db.GetView(ViewString)
	
' Create Excel Sheet
	Set xl=CreateObject("Excel.Application")
	Set xlWbk=xl.Workbooks.Add
	
' Add column headings to first row
	col=1
	Forall vColumn In v.Columns
		xlWbk.ActiveSheet.Cells(1, col)=vColumn.Title
		col=col+1
	End Forall
	
' Add row data from the documents
	row=2
	Set docX=v.GetFirstDocument
	While Not docX Is Nothing
		col=1
		Forall cValue In docX.ColumnValues
			xlWbk.ActiveSheet.Cells(row, col)=cValue
			col=col+1
		End Forall
		row=row+1
		Set docX=v.GetNextDocument(docX)
	Wend
	
' Make all columns fit
	xlWbk.ActiveSheet.Columns.AutoFit
	
	Print "Excel Document Successfully Created!"
	
' Open it up in Excel
	xl.Visible=True
	
End Sub
This was first published in March 2001

Dig deeper on Domino Resources - Part 6

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchWinIT

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchVirtualDataCentre.co.UK

Close