Export data to MS Excel from the web without OLE

This tip is very simple but it may help you to export your data to MS Excel. The whole trick is that you can create a simple text file that writes your data in a format that divides each entry with one tab. If you rename this file to *.xls, then everybody can open it with MS Excel WITHOUT any message. Each line of the text file will be a line in the first sheet in Excel and each tab in this line will be in the next column.

Advantages of such a solution:
1. You don't have to use OLE and start MS Excel.
2. Creating a text file is much faster than using OLE.
3. Such an export will also work on machines where MS Excel is not installed.
4. You can use this method for web-clients because you can let a server-side-agent run. As a result, it creates a text file but you should not try it with OLE.

The disadvantage is that you cannot do any text formatting and you cannot place it to another sheet in MS Excel.

The sample script is from a web-agent that creates the text file from a document collection. It then places this file into a new document.

Function ExportDocumentCollection (DocColl As NotesDocument ) As Integer
    Dim Doc As NotesDocument
    Dim ResultDoc As NotesDocument
    Dim FilePath As String
    Dim RTITem As NotesRichTextItem
    Dim Object As NotesEmbeddedObject
    Dim LineText As String
    Dim i As Double

    FilePath = Environ$ ("TEMP") & "Export.xls"
    Open FilePath For Output As 1

    For i=1 To DocColl.Count
       Set Doc = DocColl.GetNthDocument(i)
       LineText = Doc.Field1(0) & Chr(009) & Doc.Field2(0) & Chr(009) & Doc.Field2(0)
       Print #1, LineText

    Close 1

    Set ResultDoc = Doc.ParentDatabase.CreateDocument
    ResultDoc.Form = "Result"
    Set RTItem = New NotesRichTextItem(ResultDoc , "Export" )
    Set Object = RTitem.EmbedObject ( EMBED_ATTACHMENT, "", FilePath)
    Call ResultDoc.Save(True,False)
    Kill FilePath

End Function

This was first published in April 2001

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.