Option Public
Option Declare
Const xlAutomatic = -4105
Const xlBottom = -4107
Const xlDownThenOver = 1
Const xlGeneral = 1
Const xlLandscape = 2
Const xlPaperLegal = 5
Const xlPrintNoComments = -4142
Const xlTop = -4160
Const xlDiagonalDown = 5
Const xlDiagonalUp = 6
Const xlNone = -4142
Const xlEdgeLeft = 7
Const xlEdgeRight = 10
Const xlEdgeTop = 8
Const xlEdgeBottom = 9
Const xlContinuous = 1
Const xlThin = 2
Const xlInsideVertical = 11
Const xlInsideHorizontal = 12
Dim continue As Integer
Dim db As NotesDatabase
Dim dblRead As Double
Dim doc As NotesDocument
Dim Excel As Variant
Dim intNumberOfColumns As Integer
Dim row As Integer
Dim session As NotesSession
Dim strNow As String
Dim strViewName As String
Dim view As NotesView
Dim ws As NotesUIWorkspace
Dim xlFileName As String
Dim xlSheet As Variant
Dim xlVarFileName As Variant
Dim xlWorkbook As Variant
Sub Initialize
On Error Goto errHandler
strViewName = "People"
intNumberOfColumns = 4
Set ws = New NotesUIWorkspace
Set session = New NotesSession
Set db = session.CurrentDatabase
Set view = db.GetView( strViewName )
If view Is Nothing Then
Msgbox |Unable to open view "| & strViewName & |" ...aborting|, 16, |Error during export|
Exit Sub
End If
continue = True
Call startExcel
If Not continue Then
Call closeItDown
Exit Sub
End If
Call writeColumnHeadings
Call exportData
If continue Then Call formatOutput
Call closeItDown
Exit Sub
errHandler:
Select Case Err
Case Else
Msgbox "Error " & Str(Err) & ": " & Error$, 16, "Fatal Error...Aborting"
End Select
If Not (Excel Is Nothing) Then
On Error Resume Next
Excel.Quit
Set Excel = Nothing
End If
Exit Sub
End Sub
Sub startExcel
On Error Goto errStartExcel
strNow = Format$( Now, "ddmmmyyyy hhmm" )
xlVarFileName = ws.OpenFileDialog( False, "Where should the exported Excel file be saved?", _
"Microsoft Excel Files", "c:\", db.Title & strNow & ".xls" )
xlFileName = Lcase$( xlVarFileName(0) )
If Right$( xlFileName, 4) <> ".xls" Then
Msgbox |You must indicate a filename that ends with ".xls". Please try the export again.|, 16, "Not an Excel filename format"
continue = False
Exit Sub
End If
Print "Starting MS-Excel..."
Set Excel = CreateObject( "Excel.Application" )
Excel.Visible = False
Excel.Workbooks.Add
Set xlWorkbook = Excel.ActiveWorkbook
Set xlSheet = xlWorkbook.ActiveSheet
Exit Sub
errStartExcel:
Select Case Err
Case 184
continue = False
Exit Sub
Case 213
Msgbox "Please run the export again, this time designating a unique filename", 64, "Filename already exists"
continue = False
Resume Next
Case Else
Msgbox "Error " & Str(Err) & ": " & Error$, 16, "Fatal Error...Aborting"
continue = False
End Select
Exit Sub
End Sub
Sub writeColumnHeadings
Print "Writing column headings..."
xlSheet.Cells( 1, 1 ).Value = "Name"
xlSheet.Cells( 1, 2 ).Value = "Email"
xlSheet.Cells( 1, 3 ).Value = "Phone(s)"
xlSheet.Cells( 1, 4 ).Value = "Business"
End Sub
Sub exportData
On Error Goto errExportData
Set doc = view.GetFirstDocument
row = 1
Do While Not (doc Is Nothing)
dblRead = dblRead + 1
Print "Docs read: " & Cstr(dblRead) & "..."
row = row + 1
xlSheet.Cells( row, 1 ).Value = doc.ColumnValues(0)
xlSheet.Cells( row, 2 ).Value = doc.ColumnValues(1)
xlSheet.Cells( row, 3 ).Value = doc.OfficePhoneNumber(0)
xlSheet.Cells( row, 4 ).Value = doc.ColumnValues(3)
getNextDoc:
Set doc = view.GetNextDocument( doc )
Loop
Exit Sub
errExportData:
Select Case Err
Case 1024
Resume getNextDoc
Case Else
Msgbox "Error " & Str(Err) & ": " & Error$, 16, "Fatal Error...Aborting"
continue = False
End Select
Exit Sub
End Sub
Sub formatOutput
Print "Formatting spreadsheet; please wait..."
With xlSheet.Cells
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlTop
.WrapText = False
.Orientation = 0
.ShrinkToFit = True
.MergeCells = False
.EntireColumn.AutoFit
End With
xlSheet.Rows(1).Select
With xlSheet.Rows(1).Font
.Bold = True
.Name = "Arial"
.Size = 8
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
End With
xlSheet.Columns("A:A").Select
With xlSheet.Columns("A:A")
.WrapText = True
.ColumnWidth = 20
End With
xlSheet.Columns("B:B").Select
With xlSheet.Columns("B:B")
.WrapText = True
.ColumnWidth = 30
End With
xlSheet.Columns("C:C").Select
With xlSheet.Columns("C:C")
.WrapText = True
.ColumnWidth = 30
End With
xlSheet.Columns("D:D").Select
With xlSheet.Columns("D:D")
.WrapText = True
.ColumnWidth = 30
End With
xlSheet.Range(xlSheet.Cells(2, 1), xlSheet.Cells(row, intNumberOfColumns)).SortSpecial
With xlSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
xlSheet.PageSetup.PrintArea = ""
With xlSheet.PageSetup
.LeftHeader = _
db.Title & " - " & strViewName
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = "&F"
.CenterFooter = "&P"
.RightFooter = "&D"
.LeftMargin = Excel.InchesToPoints(0.75)
.RightMargin = Excel.InchesToPoints(0.75)
.TopMargin = Excel.InchesToPoints(1)
.BottomMargin = Excel.InchesToPoints(1)
.HeaderMargin = Excel.InchesToPoints(0.5)
.FooterMargin = Excel.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLegal
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 100
End With
xlSheet.Range("A1:D" & row).Select
xlSheet.Range("A1:D" & row).Borders(xlDiagonalDown).LineStyle = xlNone
xlSheet.Range("A1:D" & row).Borders(xlDiagonalUp).LineStyle = xlNone
With xlSheet.Range("A1:D" & row).Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With xlSheet.Range("A1:D" & row).Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With xlSheet.Range("A1:D" & row).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With xlSheet.Range("A1:D" & row).Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With xlSheet.Range("A1:D" & row).Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With xlSheet.Range("A1:D" & row).Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
xlSheet.Range("A1").Select
End Sub
Sub closeItDown
Print "Saving spreadsheet and closing MS-Excel..."
xlWorkbook.Close True, xlFileName
Excel.Quit
Set Excel = Nothing
Print " "
Msgbox Cstr(row) & " rows were exported to " & xlFileName & ".", 64, "Export DONE"
End Sub
This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.