TexasSwede
texasswede@gmail.com
  • About this blog
  • My Website
  • My Resume
  • XML Export Tool
  • Photos

Export from Notes to Excel – 3 different ways

Posted on November 14, 2012 by Karl-Henry Martinsson Posted in Lotusscript, Notes/Domino, Programming 14 Comments

While reading the developerWorks forums, I have noted that some tasks seem to be common, and users often have issues with it. One very common is to export data from Notes/Domino to Excel. My guess is that some manager/executive want to get the data to manipulate and analyze it in Excel, which they know better, and where reporting can be done easier.

First of all, for anyone that want to do real integration with Excel (or Word, or any other office program), I would suggest to look at the presentations given by John Head at Lotusphere and other conferences in the past:
Lotusphere 2011 – JMP208
IamLUG 2009 – Integration and Coexistance
Lotusphere 2006 – BP309
Lotusphere 2005 – JMP108

But if you just need to export raw data to Excel, there are a couple easy ways to do that. You don’t need to automate Excel, something the programmers posting in the forums seem to frequently do. That just makes things more complicated, and if you run the code in a server agent, Microsoft Office have to be installed on the server itself. Different versions of Excel also cause different issues.

The different methods I use to export Notes data to Excel are as follows:

  • Create a CSV file, which can be opened in Excel
  • Create a HTML table in a file with .xls extension, which can be opened in Excel
  • Create a HTML table and return it through a browser, with a content type set to open in Excel.

Depending on what the requirement is, I usually choose one of those method.

 

Method 1 – CSV file (local)

The easiest way to get data from Notes to Excel (or any other spreadsheet program) is to simply save the data as  comma-separated values (CSV). Use regular Lotusscript file operations and write the values to the file, encased in double quotes and separated by a comma. You need to build a string containing a complete line, as the Print statement adds a line break to the end automatically.

A CSV file could look like this:

FirstName,LastName,Department,StartYear
"Karl-Henry","Martinsson","IT","2002"
"John","Smith","Accounting","2009"

 

The first row is the header, with the field names listed. This helps on the receiving side, but is optional. Dates and numbers don’t need quotes around them, as long as they don’t contain commas. So make a habit to format any numbers without commas.

 

Method 2 – HTML file (local)

This method is very similar to the CSV method. The difference is that you create a table in HTML, matching the cells in Excel you want to create/populate. But instead of creating a file with the extension .htm or .html, you give it the extension .xls. Excel is intelligent enough to identify it as HTML and map the content correctly.

The biggest advantages of using a HTML file instead of CSV is that you get more control over the formatting. By using colspan and rowspan, you can merge cells together, for example in a header. You can also use markup to make cells bold or italic, or even set the text and background colors.

 

Method 3 – HTML (through browser)

This method is a variant of method 2. But instead of calling the agent inside the Notes client and creating a file somewhere in the file system, the agent is called through a URL. This means the Domino HTTP task must be enabled on the server. The URL can be called from inside the Notes client using the @URLOpen function, or the OpenURL method of the NotesUIWorkspace class.

Instead of writing to a file, use the Print statement to print to the browser. The first line printed must be the content type, so the browser realize what application to open the file in. For Excel, it looks like this:

Print "content-type:application/vnd.ms-excel"

 

It also works with (among other) “application/msexcel” and “application/xls”, but the one above is the official one, so I suggest using that.

After you print the content type, simply print the HTML table code to the browser. This will open the HTML in Excel after the agent is done. It’s that easy.

 

« IBM Notes and Domino 9.0 Social Edition
How to detect changes in fields on a form »

14 thoughts on “Export from Notes to Excel – 3 different ways”

  1. Patrick Sawyer says:
    November 14, 2012 at 17:51

    Although not automatic I have been a HUGE fan of the copy as a table function, requires precious little development time, and a little training time. Works everywhere.

    Reply
    • Karl-Henry Martinsson says:
      November 14, 2012 at 22:31

      Yes, that is a very useful function, I use it almost daily when I send out users at work links to documentation they did not read before entering IT tickets. :-)

      But the questions in teh developerWorks forums are from programmers who are trying to export Notes data into Excel, and that info might not even be in views.

      Reply
  2. Paul Withers says:
    November 15, 2012 at 07:28

    I’ve found one problem with creating HTML files that are Excel via the web, namely that Office 2007 and 2010 have added security that warns they are not valid Excel files. It’s a problem bemoaned by many on the web, including Microsoft .NET developers. The only way to avoid the error is to suppress the check via a registry setting. Copy As Table will get around that, as will using something more heavyweight like Apache POI.

    Reply
  3. Stephan H. Wissel says:
    November 19, 2012 at 00:10

    Method 4: Use the Apache POI library and create a real XLS(X) file.

    Reply
  4. Raja M says:
    March 16, 2014 at 05:30

    Is it possible to export data from Notes DB using Visual Basic 6.0.(exporting the data directly to MS access or csv). if Yes, please help

    Reply
    • Karl-Henry Martinsson says:
      March 16, 2014 at 10:25

      Absolutely. Use COM for that. The VB code would be very similar to Lotusscript code (Lotusscript i based on an older version ov VB). Contact me though email (texasswede@gmail.com) if you are interested in some help with the development, I am available for custom development.

      Reply
      • Raja M says:
        March 16, 2014 at 11:00

        That’s a great news for me… Please send me some sample code or link and i don’t have any knowledge in lotusscripts but, good in vb
        and how the server will react on its performance while using vb to extract data, because more than 500 employees will be accessing the data base

        Reply
        • Karl-Henry Martinsson says:
          March 16, 2014 at 11:31

          I sent you an email.

          Reply
  5. Mike says:
    September 26, 2014 at 14:24

    Hello Karl,
    Regarding the Method 3 – HTML (through browser) Print method using the URL, would I iterate using the $$Return or a WebQuerySave event or elsewhere (a button using JavaScript?)

    I’ve been building in Notes since ’95 but recently switched jobs and have brought up an environment where all apps are used through the browser (no fiddling with client configurations).

    Any help- would be appreciated.
    Thanks,
    Mike

    Reply
    • Karl-Henry Martinsson says:
      November 1, 2014 at 08:33

      Sorry to respond so late…
      I would put the code in a Lotusscript agent, and then call it directly on the server:
      http://www.domain.com/database.nsf/ExcelExportAgent?OpenAgent

      Reply
    • Karl-Henry Martinsson says:
      November 1, 2014 at 08:34

      You could take a look at this code:
      http://blog.texasswede.com/export-notes-view-to-excel-with-multi-value-fields/

      Reply
  6. Todor says:
    May 25, 2018 at 05:08

    Hi there,
    Do you think that will be possible to schedule export all e-mails in inbox to excel?
    What I mean – want every day to have my inbox on excel (export to csv, or different readable in excel way). If I have possibilities to automate export will stop to wonder if I missed to export, or lose time to export again. :-)
    Most important for me information can be structured in followed columns:
    1. Sender (column Who)
    2. Subject. If no subject, get all message from e-mail.
    3. Receiving date (column Date)
    4. Flag if e-mail was opened (read)

    After that I can automatize import in excel and will have copy of important information from inbox.

    Best regards
    Todor Todorov

    P.S. Just as detail (think not so important), but most e-mails was written on Cyrillic.

    Reply
  7. Todor Todorov says:
    September 7, 2018 at 08:35

    Hi again,
    Just to ask if there is a way for scheduled export.

    Best regards
    Todor Todorov

    Reply
    • Karl-Henry Martinsson says:
      September 9, 2018 at 14:41

      Todor,
      You can use method 1 and method 2 in a scheduled agent.
      Back in 2013 I posted a class I wrote that can help you export Notes views as CSV or HTML. You can find it at http://blog.texasswede.com/export-notes-view-to-excel-with-multi-value-fields/.
      If you need help creating a scheduled agent for your use, contact me at karl-henry@demandbettersolutions.com

      Reply

Leave a comment Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

HCL Ambassador 2020

HCL Ambassador 2020

IBM Champion 2014-2020

Stack Exchange

profile for Karl-Henry Martinsson on Stack Exchange, a network of free, community-driven Q&A sites

Notes/Domino Links

  • Planet Lotus Planet Lotus
  • IBM dW Forums IBM dW Forums
  • StackOverflow StackOverflow

Recent Posts

  • Notes and Domino v12 is here!
  • NTF Needs Your Help
  • Helpful Tools – Ytria EZ Suite (part 2)
  • Busy, busy – But wait: There is help!
  • Semantic UI – An alternative to Bootstrap?

Recent Comments

  • Lotus Script Multi-thread Message Box [SOLVED] – Wanted Solution on ProgressBar class for Lotusscript
  • Viet Nguyen on Keep up with COVID-19 though Domino!
  • Viet Nguyen on Keep up with COVID-19 though Domino!
  • Mark Sullivan on Looking for a HP calculator? Look no further!
  • Lynn He on About This Blog

My Pages

  • How to write better code in Notes

Archives

  • June 2021 (1)
  • April 2021 (2)
  • March 2021 (1)
  • August 2020 (3)
  • July 2020 (2)
  • April 2020 (2)
  • March 2020 (1)
  • December 2019 (2)
  • September 2019 (1)
  • August 2019 (2)
  • July 2019 (2)
  • June 2019 (3)
  • April 2019 (2)
  • December 2018 (1)
  • November 2018 (1)
  • October 2018 (5)
  • August 2018 (2)
  • July 2018 (3)
  • June 2018 (2)
  • May 2018 (1)
  • April 2018 (2)
  • March 2018 (1)
  • February 2018 (2)
  • January 2018 (4)
  • December 2017 (3)
  • November 2017 (2)
  • October 2017 (2)
  • September 2017 (1)
  • August 2017 (2)
  • July 2017 (6)
  • May 2017 (4)
  • February 2017 (1)
  • January 2017 (2)
  • December 2016 (2)
  • October 2016 (3)
  • September 2016 (4)
  • August 2016 (1)
  • July 2016 (2)
  • June 2016 (2)
  • May 2016 (3)
  • April 2016 (1)
  • March 2016 (4)
  • February 2016 (2)
  • January 2016 (4)
  • December 2015 (3)
  • November 2015 (2)
  • October 2015 (1)
  • September 2015 (2)
  • August 2015 (1)
  • July 2015 (5)
  • June 2015 (2)
  • April 2015 (2)
  • March 2015 (3)
  • February 2015 (2)
  • January 2015 (10)
  • December 2014 (1)
  • November 2014 (3)
  • October 2014 (3)
  • September 2014 (13)
  • August 2014 (6)
  • July 2014 (5)
  • May 2014 (3)
  • March 2014 (2)
  • January 2014 (10)
  • December 2013 (5)
  • November 2013 (2)
  • October 2013 (5)
  • September 2013 (4)
  • August 2013 (7)
  • July 2013 (3)
  • June 2013 (1)
  • May 2013 (4)
  • April 2013 (7)
  • March 2013 (8)
  • February 2013 (9)
  • January 2013 (5)
  • December 2012 (7)
  • November 2012 (13)
  • October 2012 (10)
  • September 2012 (2)
  • August 2012 (1)
  • July 2012 (1)
  • June 2012 (3)
  • May 2012 (11)
  • April 2012 (3)
  • March 2012 (2)
  • February 2012 (5)
  • January 2012 (14)
  • December 2011 (4)
  • November 2011 (7)
  • October 2011 (8)
  • August 2011 (4)
  • July 2011 (1)
  • June 2011 (2)
  • May 2011 (4)
  • April 2011 (4)
  • March 2011 (7)
  • February 2011 (5)
  • January 2011 (17)
  • December 2010 (9)
  • November 2010 (21)
  • October 2010 (4)
  • September 2010 (2)
  • July 2010 (3)
  • June 2010 (2)
  • May 2010 (3)
  • April 2010 (8)
  • March 2010 (3)
  • January 2010 (5)
  • November 2009 (4)
  • October 2009 (7)
  • September 2009 (1)
  • August 2009 (7)
  • July 2009 (1)
  • June 2009 (4)
  • May 2009 (1)
  • April 2009 (1)
  • February 2009 (1)
  • January 2009 (3)
  • December 2008 (1)
  • November 2008 (1)
  • October 2008 (7)
  • September 2008 (7)
  • August 2008 (6)
  • July 2008 (5)
  • June 2008 (2)
  • May 2008 (5)
  • April 2008 (4)
  • March 2008 (11)
  • February 2008 (10)
  • January 2008 (8)

Categories

  • AppDev (9)
  • Blogging (11)
    • WordPress (5)
  • Design (5)
    • Graphics (1)
    • UI/UX (2)
  • Featured (5)
  • Financial (2)
  • Food (5)
    • Baking (3)
    • Cooking (3)
  • Generic (11)
  • History (5)
  • Hobbies (10)
    • LEGO (4)
    • Photography (4)
  • Humor (1)
  • IBM/Lotus (175)
    • #Domino2025 (14)
    • #DominoForever (8)
    • #IBMChampion (46)
    • Administration (7)
    • Cloud (7)
    • CollabSphere (8)
    • Community (47)
    • Connect (33)
    • ConnectED (12)
    • Connections (3)
    • HCL (12)
    • HCL Master (1)
    • IBM Think (1)
    • Lotusphere (46)
    • MWLUG (25)
    • Notes/Domino (97)
      • Domino 11 (7)
    • Sametime (8)
    • Verse (14)
    • Volt (2)
    • Watson (6)
  • Life (8)
  • Microsoft (7)
    • .NET (2)
    • C# (1)
    • Visual Studio (1)
  • Movies (3)
  • Old Blog Post (259)
  • Personal (23)
  • Programming (83)
    • App Modernization (11)
    • Formula (4)
    • Lotusscript (46)
    • NetSuite (4)
      • SuiteScript (3)
    • node.js (4)
    • XPages (4)
  • Reviews (9)
  • Sci-Fi (4)
  • Software (24)
    • Flight Simulator (2)
    • Games (4)
    • Open Source (2)
    • Utilities (6)
  • Technology (37)
    • Aviation (3)
    • Calculators (2)
    • Computers (6)
    • Gadgets (7)
    • Mobile Phones (7)
    • Science (3)
    • Tablets (2)
  • Travel (6)
    • Texas (2)
    • United States (1)
  • Uncategorized (15)
  • Web Development (50)
    • Frameworks (23)
      • Bootstrap (14)
    • HTML/CSS (12)
    • Javascript (32)
      • jQuery (23)

Administration

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Tracking

Creeper
MediaCreeper
  • Family Pictures
© TexasSwede 2008-2014