Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

exporting names.nsf to Excel

0 views
Skip to first unread message

Philippe B

unread,
Oct 15, 2002, 4:37:07 AM10/15/02
to
I use this lotusscript in a NSF to Export a view to a Excel File via OLE. I
would like to do the same thing, but export the Informations about my
names.nsf to a Excel File. How can i open names.nsf by this database and get
the fields values ?

Regards

Philippe

Code Following :

'Get the data from the view
Dim x As Integer
Dim y As Integer
Dim strLen As Integer
Dim ses As NotesUIworkspace
Dim vw As NotesUIView
Dim coldocs As NotesDocumentCollection
Dim doc As NotesDocument
Dim it As Variant
Dim strDesc As String
Dim strTrack As String

Set ses = New NotesUIWorkspace
Set vw = ses.currentview
Set coldocs = vw.documents
Set doc = coldocs.getfirstdocument

'On cree notre lien vers EXCEL

Dim xlApp As Variant
Dim xlSheet As Variant

Set xlApp = CreateObject("Excel.application")
xlApp.Workbooks.Add

Set xlSheet = xlApp.Workbooks(1).Worksheets(1)

' Entete du tableau

xlSheet.Cells(1, 1).Value = "A"
xlSheet.Cells(1, 2).Value = "B"
xlSheet.Cells(1, 3).Value = "C"
xlSheet.Cells(1, 4).Value = "D"
xlSheet.Cells(1, 5).Value = "E"
xlSheet.Cells(1, 6).Value = "F"
xlSheet.Cells(1, 7).Value = "G"
xlSheet.Cells(1, 8).Value = "H"
xlSheet.Cells(1, 9).Value = "I"
xlSheet.Cells(1, 10).Value = "J"

' Largeur des colonnes. En commentaires car l on passe en largeur
automatique

' xlSheet.Columns(1).Columnwidth = 193
' xlSheet.Columns(2).Columnwidth = 100
' xlSheet.Columns(2).Columnheight = 10
' xlSheet.Columns(3).Columnwidth = 150
' xlSheet.Columns(4).Columnwidth = 16.75
' xlSheet.Columns(5).Columnwidth = 11.5
' xlSheet.Columns(6).Columnwidth = 9.29
' xlSheet.Columns(7).Columnwidth = 24
' xlSheet.Columns(8).Columnwidth = 45

' Alignement vertical

xlSheet.Columns(1).VerticalAlignment = 1
xlSheet.Columns(2).VerticalAlignment = 1
xlSheet.Columns(3).VerticalAlignment = 1
xlSheet.Columns(4).VerticalAlignment = 1
xlSheet.Columns(5).VerticalAlignment = 1
xlSheet.Columns(6).VerticalAlignment = 1
xlSheet.Columns(7).VerticalAlignment = 1
xlSheet.Columns(8).VerticalAlignment = 1
xlSheet.Columns(9).VerticalAlignment = 1
xlSheet.Columns(10).VerticalAlignment = 1


' Format portrait ou paysage

'1 = Portrait
'2 = Landscape

xlSheet.PageSetup.Orientation = 2

'On souligne les entetes

xlsheet.Cells(1, 1).Font.Bold = 1
xlsheet.Cells(1, 2).Font.Bold = 1
xlsheet.Cells(1, 3).Font.Bold = 1
xlsheet.Cells(1, 4).Font.Bold = 1
xlsheet.Cells(1, 5).Font.Bold = 1
xlsheet.Cells(1, 6).Font.Bold = 1
xlsheet.Cells(1, 7).Font.Bold = 1
xlsheet.Cells(1, 8).Font.Bold = 1
xlsheet.Cells(1, 9).Font.Bold = 1
xlsheet.Cells(1, 10).Font.Bold = 1

' On declare la premiere repetee a l impression

' xlsheet.PageSetup.PrintTitleRows = "$1:$1"

xlsheet.Columns(2).NumberFormat = "################################"
xlsheet.Columns(6).NumberFormat = "@"

'-Set the page size to 80%
'When printing, this assures that all the columns will fit on one page
'You may need to experiment with this a little to find what size is right
for your
'data, or maybe you don't need it to fit on one printed page.
xlsheet.PageSetup.Zoom = 80

'output the data
'This is set up this way to start the outputed data at the 3rd row (I have
my
'header row, and one blank row at the top of my page for looks, you can
alter
'this value to start anywhere you want, but be sure that the next statement
'is always coldocs.count + 1 more than the first number
'(i.e. "for x = 5 to (coldocs.count + 6)")
For x = 3 To (coldocs.count + 2)
'These are your values you want outputed...the second number will be the
'column you want them in, the value after the "=" is a field on doc (which
'is the selected document that's currently being processed)

' If doc.dos = "DOS" Then doc.dos = "X"


xlSheet.Cells(x, 1).Value = doc.a
xlSheet.Cells(x, 2).Value = doc.b
xlSheet.Cells(x, 3).Value = doc.c
xlSheet.Cells(x, 4).Value = doc.d
xlSheet.Cells(x, 5).Value = doc.e
xlSheet.Cells(x, 6).Value = doc.f
xlSheet.Cells(x, 7).Value = doc.g
xlSheet.Cells(x, 8).Value = doc.h
xlSheet.Cells(x, 9).Value = doc.i
xlSheet.Cells(x, 10).Value = doc.j

'Get the next document in our collection of selected docs
Set doc = coldocs.GetNextDocument(doc)

Next x

xlSheet.Columns("A:A").Select
xlApp.Selection.Columns.autofit
xlSheet.Columns("B:B").Select
xlApp.Selection.Columns.autofit
xlSheet.Columns("C:C").Select
xlApp.Selection.Columns.autofit
xlSheet.Columns("D:D").Select
xlApp.Selection.Columns.autofit
xlSheet.Columns("E:E").Select
xlApp.Selection.Columns.autofit
xlSheet.Columns("F:F").Select
xlApp.Selection.Columns.autofit
xlSheet.Columns("G:G").Select
xlApp.Selection.Columns.autofit
xlSheet.Columns("H:H").Select
xlApp.Selection.Columns.autofit
xlSheet.Columns("I:I").Select
xlApp.Selection.Columns.autofit
xlSheet.Columns("J:J").Select
xlApp.Selection.Columns.autofit


'Display a message telling the user their file is ready
Msgbox "Votre fichier EXCEL est prêt !", 64, "Exportation EXCEL"

'Show the excel application we started in the background
xlApp.Visible = True


0 new messages