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
    Next

    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

Dig deeper on Domino Resources - Part 7

0 comments

Oldest 

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:

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchDataCenter

SearchExchange

SearchContentManagement

Close