This can be achieved using NotesViewNavigator and NotesViewEntry (IsCategory property).
Walk through the view using navigator , get entry and check if it is a category, then export that row into a view.
~Hemanth
Main Topics
Browse All TopicsGreetings learned one,
I have a view that contains categorized views which show the subtotals for each month for each product which then roll down to a grand total. I know you could the categorized rows and selecting File - Export ..., but the customer would like to have this automated. Is there LS code available that I can use to only export those categorized rows or another way to present the view? For example,
Prod A Prod B Prod C
Jan 2 3 4 <-- just want this row
1/10/07 1 2 3
1/25/07 1 1 1
Feb 5 6 7 <-- just want this row
2/14/07 2 2 4
2/15/07 3 4 3
Thank you.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Well, easy enough to convert a standard excel export to do view navigator and columnentries. Here's a quick adaptation of my standard excel export using view navigators.
Now this one loops through all the columns, and doesn't skip any.. which means if you have columns that are not rolled up into the category totals, the column will be there but not a value. Also, this has some automatic formatting based on the value of the columns, so if the column value type is number, it will format a number. If it's a date it will format a date.
Agent Information
Name: Export View Categories to Excel
Type: LotusScript
State: Enabled
Trigger: Manually From Actions Menu
Acts On: All documents in view
LotusScript Code:
Option Public
Option Declare
Dim session As Variant
Dim ws As Variant
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim view As NotesView
Dim vname As String
Dim vcols As Variant
Dim uvcols As Integer
Dim rows, cols, maxcols, x As Integer
Dim result As Variant
Dim trackCols() As String
Dim theTitles() As String
Dim viewName As String
Dim errorFLAG As Integer
Dim xlApp As Variant
Dim xlSheet As Variant
Dim excelTitle As String
Dim excelCompany As String
Dim continue As Variant
Const xlWorkbookNormal = -4143
Const xlEdgeBottom = 9
Const xlContinuous = 1
Const xlThin = 2
Const xlEdgeTop = 8
Const xlThick = 4
Const fontName="Arial"
Dim cRGBCream As Long, cRGBBlue As Long, cRGBBlack As Long,cRGBRED As Long, cRGBYellow As Long
Dim cRGBGrey As Long,cRGBLTBlue As Long,cRGBMedBlue As Long
Const fmtGeneral="General"
Const fmtCurrency="#,##0;[Red](#
Const fmtNumber="#,##0;[Red](#,#
Const fmtPercent="#,##0.0%;[Red]
Const fmtGM="#,##0.00;[Red](#,##
Const fmtCustID="00000000"
Const fmtMarkup="#,#0.00;[Red]-#
Sub Initialize
'Export Entire View Documents Agent
On Error Goto ErrorHandler
Continue = True
Set session = New NotesSession
Set db = session.currentdatabase
Set ws =New NotesUIworkspace
Dim view As NotesView
Dim uiview As NotesUIView
Set uiview = ws.currentview
Dim numdocs As Integer
Dim platform As String
Dim thisTitle As String
viewname = ws.currentview.viewname
Set view = db.getView(viewName)
If view Is Nothing Then
Msgbox "Sorry, there was an error loading this view. " + Chr(10) + "Please contact the database administrator",,"Error loading view"
Exit Sub
End If
'Creating colors for format
cRGBCream= makeRGB(255,224,191)
cRGBBlue=makeRGB(0,0,80)
cRGBBlack=makeRGB(0,0,0)
cRGBRed = makeRGB(208,0,0)
cRGBGrey=makeRGB(240,240,2
cRGBYellow=makeRGB(255,255
cRGBLtBlue=makeRGB(224,255
cRGBMedBlue = makeRGB(0,0,255)
'Check to see if the user is on a MacIntosh
'the "Create Object" function does not run on a Mac
platform = session.Platform
If Not Instr (platform, "MacIntosh") = 0 Then
Messagebox ("This function cannot be run on a MacIntosh. Please use a PC to pull this data into a spreadsheet.")
Exit Sub
End If
Dim nav As NotesViewNavigator
Dim entry As NotesViewEntry
Dim colEntries As Variant
'Get all selected docs from the view or the entire view
numdocs = view.allentries.count
Dim i As Long
Dim j As Long
'Get the number of columns in the view, and store the column headings in an array
vcols = view.Columns
uvcols = Ubound(vcols)
Redim theTitles(uvCols+1) As String
'Create the Excel spreadsheet, hide it from the UI, and add a new workbook
Set xlApp = CreateObject("Excel.Applic
xlApp.Visible = False 'hide Excel while processing
xlApp.Workbooks.Add
'Set the Excel row and column heading to R1C1 reference style so that we can loop with numbers instead of letters
xlApp.ReferenceStyle = 2
Set xlSheet = xlApp.Workbooks(1).Workshe
xlSheet.Name = "Lotus Export"
rows = 1
cols = 1
'Enter the view column headings into the spreadsheet, skipping hidden columns and columns without titles.
'Rows stay constant at 1 while columns is incremented by 1 for each view column
With xlSheet
For x = 0 To uvcols
If vcols(x).IsHidden = False Then
If vcols(x).Title = "" Then
.Cells(rows, cols).Value = "COL " + Cstr(cols)
theTitles(cols) = "COL " + Cstr(cols)
cols = cols + 1
Else
.Cells(rows, cols).Value = Trim(vcols(x).Title)
theTitles(cols) = Ucase(Trim(vcols(x).Title)
cols = cols + 1
End If
End If
Next
maxcols = cols - 1
Redim trackCols(maxCols)
'Export Categories to excel worksheet
Set nav = view.CreateViewNav
Set entry = nav.GetFirst
rows = 2
cols = 1
Print "Exporting category documents to Excel..."
While Not entry Is Nothing
If entry.isCategory Then
colEntries = entry.ColumnValues
Forall ce In colEntries
If ce <> "" Then
.Cells(rows, cols).Value = ce
Else
.Cells(rows, cols).Value = ""
End If
'Always increment to be consistent with loop for col titles
cols = cols + 1
End Forall
rows = rows + 1
cols = 1
End If
Set entry = nav.GetNextCategory(entry)
Wend
End With
Set doc = Nothing
Set view = Nothing
On Error Goto ExcelFormatError
Print "Formatting Excel Spreadsheet..."
Call formatSpreadsheet
ExitHere:
'Release Excel app and workbook if there is an error, otherwise memory will get clogged with versions of Excel running
If Not Continue Then
xlApp.Visible = False
xlApp.Workbooks(1).close(F
xlApp.quit
Else
If Not xlapp Is Nothing Then
xlApp.Visible = True 'Show Excel in the UI when done processing
End If
End If
Set xlApp = Nothing
Set xlSheet = Nothing
Exit Sub
ErrorHandler:
Msgbox "Error #" & Format$(Err) & " at line " & Format$(Erl) & ": " & Error$, 0, "Error Processing Excel Export"
Continue = False
If Not xlapp Is Nothing Then
'Release Excel app and workbook if there is an error, otherwise memory will get clogged with versions of Excel running
xlApp.Workbooks(1).close(F
xlapp.quit
Set xlApp = Nothing
Set xlSheet = Nothing
End If
Exit Sub
ExcelFormatError:
Msgbox "There was a general excel export error: " + Error$ + "-" + Str(Err), 0, "Error Processing Excel Export"
Continue = False
If Not xlapp Is Nothing Then
'Release Excel app and workbook if there is an error, otherwise memory will get clogged with versions of Excel running
xlApp.Workbooks(1).close(F
xlapp.quit
Set xlApp = Nothing
Set xlSheet = Nothing
End If
Exit Sub
End Sub
Sub Terminate
End Sub
Sub FormatSpreadsheet
'Format the appearance of the Excel spreadsheet:
'Select all cells and format
'General Cell Format
xlApp.Range(xlSheet.Cells(
xlApp.Selection.Font.Name = "Arial"
xlApp.Selection.Font.Size = 8
xlApp.Selection.Font.Color
xlApp.Selection.Columns.Au
xlApp.Selection.RowHeight = 13
'Top Row
xlApp.Range(xlSheet.Cells(
xlApp.Selection.Font.Bold = True
xlApp.Selection.Font.Name = "Arial"
xlApp.Selection.Font.Size = 9
xlApp.Selection.Font.Color
xlApp.Selection.RowHeight = 15
xlApp.Selection.Interior.c
With xlApp.Selection.Borders(xl
.color = cRGBBlack
.LineStyle = xlContinuous
.Weight = xlThin
End With
With xlApp.Selection.Borders(xl
.LineStyle = xlContinuous
.Weight = xlThin
.color = cRGBBlack
End With
With xlApp.Selection.Borders(xl
.LineStyle = xlContinuous
.Weight = xlThick
.color = cRGBBlack
End With
'format the NUMERIC Columns using the TrackCols array
Dim thisFormat As String
For x = Lbound(theTitles) To Ubound(theTitles)
thisFormat = ""
Select Case Ucase(TrackCols(x))
Case "NUMBER"
thisFormat = fmtNumber
Case "ID"
thisFormat = fmtCustID
Case Else
'do nothing
End Select
If thisFormat <>"" Then
xlApp.Range(xlSheet.Cells(
End If
Next
Dim sumString As String
'Format the column numbers
For x = Lbound(theTitles) To Ubound(theTitles)
thisFormat = ""
sumString = {R} + Cstr(2) + {C} + Cstr(x) + ":" + {R} + Cstr(rows-1) + {C} + Cstr(x)
Select Case Ucase(trackCols(x))
Case "NUMBER"
xlApp.Cells(rows,x).formul
xlApp.Range(xlSheet.Cells(
Case Else
'do nothing
End Select
Next
With xlApp.Worksheets(1).PageSe
.Orientation = 2
If excelTitle= "" Then
.CenterHeader =viewname + " Report - Confidential"
Else
.CenterHeader = excelTitle + " - Confidential"
End If
.RightFooter = "&R Page &P of &N"
.LeftFooter = Format(Now(),"mm/dd/yyyy hh:mm AM/PM")
If excelCompany = "" Then
.CenterFooter = "Export from Lotus Notes by" + session.commonusername
Else
.CenterFooter = "&B" + excelCompany + "&B"
End If
'.PrintArea =myRange
.PrintTitleRows = xlApp.Rows(1).Address
.LeftMargin = xlApp.InchesToPoints(0.35)
.RightMargin = xlApp.InchesToPoints(0.35)
.TopMargin = xlApp.InchesToPoints(1)
.BottomMargin = xlApp.InchesToPoints(1)
.HeaderMargin = xlApp.InchesToPoints(0.5)
.FooterMargin = xlApp.InchesToPoints(0.5)
End With
Stop
'Set the Excel row and col heading back to the AI Reference Style where the cols are lettered and the rows are numbered
xlApp.ReferenceStyle = 1
xlApp.Range("B:B").Select
With xlapp.selection
.NumberFormat = "[$-F800]dddd, mmmm dd, yyyy"
.Font.Name = "Arial"
.Font.Size = 8
.Font.FontStyle = "Bold"
.Font.Color = cRGBMedBlue
End With
End Sub
Function MakeRGB(Red As Integer ,Green As Integer, Blue As Integer) As Long
MakeRGB = (((&H100& * Green) Or Red) Or (&H10000 * Blue))
End Function
Aw, darn.. few blunders in the above.. forgot to add the trackcols value to add the subtotal to the end of the spreadsheet. This one should do it.
Agent Information
Name: Export View Categories to Excel
Type: LotusScript
State: Enabled
Trigger: Manually From Actions Menu
Acts On: All documents in view
LotusScript Code:
Option Public
Option Declare
Dim session As Variant
Dim ws As Variant
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim view As NotesView
Dim vname As String
Dim vcols As Variant
Dim uvcols As Integer
Dim rows, cols, maxcols, x As Integer
Dim result As Variant
Dim trackCols() As String
Dim theTitles() As String
Dim viewName As String
Dim errorFLAG As Integer
Dim xlApp As Variant
Dim xlSheet As Variant
Dim excelTitle As String
Dim excelCompany As String
Dim continue As Variant
Const xlWorkbookNormal = -4143
Const xlEdgeBottom = 9
Const xlContinuous = 1
Const xlThin = 2
Const xlEdgeTop = 8
Const xlThick = 4
Const fontName="Arial"
Dim cRGBCream As Long, cRGBBlue As Long, cRGBBlack As Long,cRGBRED As Long, cRGBYellow As Long
Dim cRGBGrey As Long,cRGBLTBlue As Long,cRGBMedBlue As Long
Const fmtGeneral="General"
Const fmtCurrency="#,##0;[Red](#
Const fmtNumber="#,##0;[Red](#,#
Const fmtPercent="#,##0.0%;[Red]
Const fmtGM="#,##0.00;[Red](#,##
Const fmtCustID="00000000"
Const fmtMarkup="#,#0.00;[Red]-#
Sub Initialize
'Export Entire View Documents Agent
On Error Goto ErrorHandler
Continue = True
Set session = New NotesSession
Set db = session.currentdatabase
Set ws =New NotesUIworkspace
Dim view As NotesView
Dim uiview As NotesUIView
Set uiview = ws.currentview
Dim numdocs As Integer
Dim platform As String
Dim thisTitle As String
viewname = ws.currentview.viewname
Set view = db.getView(viewName)
If view Is Nothing Then
Msgbox "Sorry, there was an error loading this view. " + Chr(10) + "Please contact the database administrator",,"Error loading view"
Exit Sub
End If
'Creating colors for format
cRGBCream= makeRGB(255,224,191)
cRGBBlue=makeRGB(0,0,80)
cRGBBlack=makeRGB(0,0,0)
cRGBRed = makeRGB(208,0,0)
cRGBGrey=makeRGB(240,240,2
cRGBYellow=makeRGB(255,255
cRGBLtBlue=makeRGB(224,255
cRGBMedBlue = makeRGB(0,0,255)
'Check to see if the user is on a MacIntosh
'the "Create Object" function does not run on a Mac
platform = session.Platform
If Not Instr (platform, "MacIntosh") = 0 Then
Messagebox ("This function cannot be run on a MacIntosh. Please use a PC to pull this data into a spreadsheet.")
Exit Sub
End If
Dim nav As NotesViewNavigator
Dim entry As NotesViewEntry
Dim colEntries As Variant
'Get all selected docs from the view or the entire view
numdocs = view.allentries.count
Dim i As Long
Dim j As Long
'Get the number of columns in the view, and store the column headings in an array
vcols = view.Columns
uvcols = Ubound(vcols)
Redim theTitles(uvCols+1) As String
'Create the Excel spreadsheet, hide it from the UI, and add a new workbook
Set xlApp = CreateObject("Excel.Applic
xlApp.Visible = False 'hide Excel while processing
xlApp.Workbooks.Add
'Set the Excel row and column heading to R1C1 reference style so that we can loop with numbers instead of letters
xlApp.ReferenceStyle = 2
Set xlSheet = xlApp.Workbooks(1).Workshe
xlSheet.Name = "Lotus Export"
rows = 1
cols = 1
'Enter the view column headings into the spreadsheet, skipping hidden columns and columns without titles.
'Rows stay constant at 1 while columns is incremented by 1 for each view column
With xlSheet
For x = 0 To uvcols
If vcols(x).IsHidden = False Then
If vcols(x).Title = "" Then
.Cells(rows, cols).Value = "COL " + Cstr(cols)
theTitles(cols) = "COL " + Cstr(cols)
cols = cols + 1
Else
.Cells(rows, cols).Value = Trim(vcols(x).Title)
theTitles(cols) = Ucase(Trim(vcols(x).Title)
cols = cols + 1
End If
End If
Next
maxcols = cols - 1
Redim trackCols(maxCols)
'Export Categories to excel worksheet
x=0
Dim doOnce As Boolean
doOnce = True
Set nav = view.CreateViewNav
Set entry = nav.GetFirst
rows = 2
cols = 1
Print "Exporting category documents to Excel..."
While Not entry Is Nothing
If entry.isCategory Then
colEntries = entry.ColumnValues
Forall ce In colEntries
If ce <> "" Then
If doOnce Then
trackcols(x) = Typename ( ce )
End If
.Cells(rows, cols).Value = ce
Else
.Cells(rows, cols).Value = ""
End If
'Always increment to be consistent with loop for col titles
cols = cols + 1
x = x +1
End Forall
doOnce = False
rows = rows + 1
cols = 1
End If
Set entry = nav.GetNextCategory(entry)
Wend
End With
Set doc = Nothing
Set view = Nothing
On Error Goto ExcelFormatError
Print "Formatting Excel Spreadsheet..."
Call formatSpreadsheet
ExitHere:
'Release Excel app and workbook if there is an error, otherwise memory will get clogged with versions of Excel running
If Not Continue Then
xlApp.Visible = False
xlApp.Workbooks(1).close(F
xlApp.quit
Else
If Not xlapp Is Nothing Then
xlApp.Visible = True 'Show Excel in the UI when done processing
End If
End If
Set xlApp = Nothing
Set xlSheet = Nothing
Exit Sub
ErrorHandler:
Msgbox "Error #" & Format$(Err) & " at line " & Format$(Erl) & ": " & Error$, 0, "Error Processing Excel Export"
Continue = False
If Not xlapp Is Nothing Then
'Release Excel app and workbook if there is an error, otherwise memory will get clogged with versions of Excel running
xlApp.Workbooks(1).close(F
xlapp.quit
Set xlApp = Nothing
Set xlSheet = Nothing
End If
Exit Sub
ExcelFormatError:
Msgbox "There was a general excel export error: " + Error$ + "-" + Str(Err), 0, "Error Processing Excel Export"
Continue = False
If Not xlapp Is Nothing Then
'Release Excel app and workbook if there is an error, otherwise memory will get clogged with versions of Excel running
xlApp.Workbooks(1).close(F
xlapp.quit
Set xlApp = Nothing
Set xlSheet = Nothing
End If
Exit Sub
End Sub
Sub Terminate
End Sub
Sub FormatSpreadsheet
'Format the appearance of the Excel spreadsheet:
'Select all cells and format
'General Cell Format
xlApp.Range(xlSheet.Cells(
xlApp.Selection.Font.Name = "Arial"
xlApp.Selection.Font.Size = 8
xlApp.Selection.Font.Color
xlApp.Selection.Columns.Au
xlApp.Selection.RowHeight = 13
'Top Row
xlApp.Range(xlSheet.Cells(
xlApp.Selection.Font.Bold = True
xlApp.Selection.Font.Name = "Arial"
xlApp.Selection.Font.Size = 9
xlApp.Selection.Font.Color
xlApp.Selection.RowHeight = 15
xlApp.Selection.Interior.c
With xlApp.Selection.Borders(xl
.color = cRGBBlack
.LineStyle = xlContinuous
.Weight = xlThin
End With
With xlApp.Selection.Borders(xl
.LineStyle = xlContinuous
.Weight = xlThin
.color = cRGBBlack
End With
With xlApp.Selection.Borders(xl
.LineStyle = xlContinuous
.Weight = xlThick
.color = cRGBBlack
End With
'format the NUMERIC Columns using the TrackCols array
Dim thisFormat As String
For x = Lbound(theTitles) To Ubound(theTitles)
thisFormat = ""
Select Case Ucase(TrackCols(x))
Case "NUMBER","DOUBLE","LONG","
thisFormat = fmtNumber
Case "CURRENCY"
thisFormat = fmtCurrency
Case Else
'do nothing
End Select
If thisFormat <>"" Then
xlApp.Range(xlSheet.Cells(
End If
Next
Dim sumString As String
'Format the column numbers
For x = Lbound(theTitles) To Ubound(theTitles)
thisFormat = ""
sumString = {R} + Cstr(2) + {C} + Cstr(x+1) + ":" + {R} + Cstr(rows-1) + {C} + Cstr(x+1)
Select Case Ucase(trackCols(x))
Case "NUMBER","DOUBLE","LONG","
xlApp.Cells(rows,x+1).form
xlApp.Range(xlSheet.Cells(
Case Else
'do nothing
End Select
Next
With xlApp.Worksheets(1).PageSe
.Orientation = 2
If excelTitle= "" Then
.CenterHeader =viewname + " Report - Confidential"
Else
.CenterHeader = excelTitle + " - Confidential"
End If
.RightFooter = "&R Page &P of &N"
.LeftFooter = Format(Now(),"mm/dd/yyyy hh:mm AM/PM")
If excelCompany = "" Then
.CenterFooter = "Export from Lotus Notes by" + session.commonusername
Else
.CenterFooter = "&B" + excelCompany + "&B"
End If
'.PrintArea =myRange
.PrintTitleRows = xlApp.Rows(1).Address
.LeftMargin = xlApp.InchesToPoints(0.35)
.RightMargin = xlApp.InchesToPoints(0.35)
.TopMargin = xlApp.InchesToPoints(1)
.BottomMargin = xlApp.InchesToPoints(1)
.HeaderMargin = xlApp.InchesToPoints(0.5)
.FooterMargin = xlApp.InchesToPoints(0.5)
End With
Stop
'Set the Excel row and col heading back to the AI Reference Style where the cols are lettered and the rows are numbered
xlApp.ReferenceStyle = 1
xlApp.Range("B:B").Select
With xlapp.selection
.NumberFormat = "[$-F800]dddd, mmmm dd, yyyy"
.Font.Name = "Arial"
.Font.Size = 8
.Font.FontStyle = "Bold"
.Font.Color = cRGBMedBlue
End With
End Sub
Function MakeRGB(Red As Integer ,Green As Integer, Blue As Integer) As Long
MakeRGB = (((&H100& * Green) Or Red) Or (&H10000 * Blue))
End Function
Business Accounts
Answer for Membership
by: sjef_bosmanPosted on 2007-01-28 at 09:46:59ID: 18414922
To give you some general ideas:
http:Q_21079422.html "How to look up subtotals from a view into a form??"
http:Q_20501853.html "Export to CVS file"