Tip

Export A View To Xls File

This script export a notes view to a XLS file automatically !
Sub ExportXLS(Vue As String, Fichier As Variant)

'----------------------- Declarations ----------------------------------

Dim Session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument

Dim nbcol As Integer
Dim i,k As Variant
Dim Handle As Variant
Dim Wbook, Wsheet As Variant
Dim column As NotesViewColumn


'-------------------------------------------------------------------------------

Set db=Session.CurrentDatabase
Set view=db.Getview(Vue)

Set Handle=CreateObject("Excel.Application")
Set Wbook=Handle.Workbooks.Add
Set WSheet=Wbook.Worksheets(1)

k=0
nbcol = Ubound(view.Columns)

' Affiche le nom des colonnes dans la premi?re ligne du fichier Excel
Do

Set column=view.Columns(k)
Wsheet.Cells(1, k+1).Value=column.Title
k=k+1

Loop Until k=nbcol+1

' Remplit les cellules du fichiers avec les diff?rentes valeurs qui se
trouvent dans la vue
i=2
Set doc=view.Getfirstdocument()

While Not (doc Is Nothing)
For k = 0 To nbcol
Wsheet.Cells(i,k+1).Value=doc.ColumnValues(k)
Next

Set doc = view.GetNextDocument(doc)
i = i + 1
Wend

' Mise en page
Wsheet.Rows(1).Font.Bold=True
Wsheet.Rows(1).Font.Size=12

For k=1 To nbcol+1
Wsheet.Columns(k).Autofit
Next

Wbook.SaveAs(Fichier)
Wbook.close
Handle.Quit

Set Worksheet=Nothing
Set Workbook=Nothing
Set Handle=Nothing

End Sub

This was first published in November 2000

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

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:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.