Question

Programatically export only categorized rows to spreadsheet

Asked by: notesrookie

Greetings 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.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2007-01-28 at 09:19:46ID22139776
Tags

export

Topic

Lotus Notes

Participating Experts
3
Points
250
Comments
11

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

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.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

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.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

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.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Categorizing documents
    Hello. We use the MS Office Documents template at work to keep track of many of our documents. Customers are used as categorize criteria, but we miss the opportunity to have several sub-categories. Is it possible to modify the template or does someone know about a similar d...
  2. Categorizer Retry Error
    We have a fairly large sized Exchange organization with more than 10 trees in a forest, with each tree having an Exchange Admin group and at least 2 routing groups (one for backup) for each admin group. Each tree has their own registered SMTP domains. One particular tree (ex...
  3. Remove (Not Categorized) from Categorized View
    I have a Categorized view that has two categories. Is there a way to remove the (Not Categorized) if there is no subcategory? It looks like this now. > = Twistie >Category > (Not Categorized) Apples Pears > Animals Bears Lions I ...
  4. Categorize graphs
    I have a spreadsheet that shows a percentage of accuracy for 70 different records. Instead of have 70 different bars with a percentage, I'd like to have one bar that shows all the percentages with 90% and better, one with 80-89%, one with 70-79% and so on. How can I do this?

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

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.

Join the Community

Answers

 

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"

 

by: HemanthaKumarPosted on 2007-01-28 at 15:36:10ID: 18416019

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

 

by: marilyngPosted on 2007-01-28 at 16:19:02ID: 18416151

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](#,##0)"
Const fmtNumber="#,##0;[Red](#,##0)"
Const fmtPercent="#,##0.0%;[Red](#,##0.0%)"
Const fmtGM="#,##0.00;[Red](#,##0.00)"
Const fmtCustID="00000000"
Const fmtMarkup="#,#0.00;[Red]-#,##0.00"
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,240)
      cRGBYellow=makeRGB(255,255,192)
      cRGBLtBlue=makeRGB(224,255,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.Application")
      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).Worksheets(1)
      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(False)            
            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(False)      
            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(False)      
            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(1,1), xlsheet.Cells(rows+2,maxcols)).Select
      xlApp.Selection.Font.Name = "Arial"
      xlApp.Selection.Font.Size = 8
      xlApp.Selection.Font.Color = cRGBBlack
      xlApp.Selection.Columns.AutoFit
      xlApp.Selection.RowHeight = 13
      'Top Row
      xlApp.Range(xlSheet.Cells(1,1), xlSheet.Cells(1, maxcols)).Select      
      xlApp.Selection.Font.Bold = True
      xlApp.Selection.Font.Name = "Arial"
      xlApp.Selection.Font.Size = 9
      xlApp.Selection.Font.Color = cRGBBlack
      xlApp.Selection.RowHeight = 15
      xlApp.Selection.Interior.color = cRGBGrey
      With xlApp.Selection.Borders(xlEdgeBottom)
            .color =  cRGBBlack            
            .LineStyle = xlContinuous
            .Weight = xlThin
      End With
      With xlApp.Selection.Borders(xlEdgeBottom)            
            .LineStyle = xlContinuous
            .Weight = xlThin
            .color =  cRGBBlack            
      End With
      With xlApp.Selection.Borders(xlEdgeTop)            
            .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(2,x), xlsheet.Cells(rows,x)).NumberFormat = thisFormat
            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).formula={=SUM(} + sumString + {)}
                  xlApp.Range(xlSheet.Cells(2,x), xlsheet.Cells(rows,x)).NumberFormat = fmtNumber
            Case Else
                  'do nothing
            End Select            
      Next
      With xlApp.Worksheets(1).PageSetup
            .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
      

 

by: marilyngPosted on 2007-01-28 at 16:59:28ID: 18416279

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](#,##0)"
Const fmtNumber="#,##0;[Red](#,##0)"
Const fmtPercent="#,##0.0%;[Red](#,##0.0%)"
Const fmtGM="#,##0.00;[Red](#,##0.00)"
Const fmtCustID="00000000"
Const fmtMarkup="#,#0.00;[Red]-#,##0.00"
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,240)
      cRGBYellow=makeRGB(255,255,192)
      cRGBLtBlue=makeRGB(224,255,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.Application")
      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).Worksheets(1)
      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(False)            
            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(False)      
            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(False)      
            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(1,1), xlsheet.Cells(rows+2,maxcols)).Select
      xlApp.Selection.Font.Name = "Arial"
      xlApp.Selection.Font.Size = 8
      xlApp.Selection.Font.Color = cRGBBlack
      xlApp.Selection.Columns.AutoFit
      xlApp.Selection.RowHeight = 13
      'Top Row
      xlApp.Range(xlSheet.Cells(1,1), xlSheet.Cells(1, maxcols)).Select      
      xlApp.Selection.Font.Bold = True
      xlApp.Selection.Font.Name = "Arial"
      xlApp.Selection.Font.Size = 9
      xlApp.Selection.Font.Color = cRGBBlack
      xlApp.Selection.RowHeight = 15
      xlApp.Selection.Interior.color = cRGBGrey
      With xlApp.Selection.Borders(xlEdgeBottom)
            .color =  cRGBBlack            
            .LineStyle = xlContinuous
            .Weight = xlThin
      End With
      With xlApp.Selection.Borders(xlEdgeBottom)            
            .LineStyle = xlContinuous
            .Weight = xlThin
            .color =  cRGBBlack            
      End With
      With xlApp.Selection.Borders(xlEdgeTop)            
            .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","INTEGER"
                  thisFormat = fmtNumber
            Case "CURRENCY"
                  thisFormat = fmtCurrency
            Case Else
                  'do nothing                  
            End Select
            If thisFormat <>"" Then
                  xlApp.Range(xlSheet.Cells(2, x+1), xlsheet.Cells(rows, x+1)).NumberFormat = thisFormat
            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","INTEGER","CURRENCY"
                  xlApp.Cells(rows,x+1).formula={=SUM(} + sumString + {)}
                  xlApp.Range(xlSheet.Cells(2,x+1), xlsheet.Cells(rows,x+1)).NumberFormat = fmtNumber
            Case Else
                  'do nothing
            End Select            
      Next
      With xlApp.Worksheets(1).PageSetup
            .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
            

 

by: sjef_bosmanPosted on 2007-01-29 at 01:11:53ID: 18417745

Hey Hemantha, welcome back!

 

by: marilyngPosted on 2007-01-29 at 06:32:08ID: 18419386

Sorry, I was busy testing my solution when you posted, Hemantha.   So I didn't see your comment.  But that's basically what I did.

 

by: notesrookiePosted on 2007-01-29 at 09:51:09ID: 18421267

Thanks, marilyng. Your solution worked exquisitely.

 

by: sjef_bosmanPosted on 2007-01-29 at 12:21:50ID: 18422559

I assume no one basically bothered to follow the links I posted? Plenty NotesViewNavigators and Entries in there...

 

by: marilyngPosted on 2007-01-29 at 16:09:29ID: 18424108

sjef, I did check those out, and, yes, there was a view nav example, and an export example.  But nothing to excel, which is why I posted a sub from my excel export script library.

 

by: sjef_bosmanPosted on 2007-01-30 at 00:42:42ID: 18426011

Excel? Now who said Excel??  ;-)

 

by: marilyngPosted on 2007-01-30 at 10:46:14ID: 18430008

I just assumed excel export... just in case...  :)

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...