Falling Dominos | Let's keep Lotus Notes development relevant

Gridlines for Printing Excel from a Web Agent

Have you ever noticed that Microsoft Excel content printed from a Web Agent usually doesn’t have gridlines. You can put borders around your data by adding border=1 (or whatever) but it still doesn’t show the default gridlines.

The is the only way I have found to add gridlines is by adding some Microsoft XML settings in the header. I found the code on one of those “Expert Exchange” forums but it’s almost impossible to link to it without paying the fee.

Here is the code. I return the full header in a string. You really only need to pay attention to what is between the tags.

    Public Function getHeader() As String
        getHeader=  |Content-Type:application/vnd.ms-excel| & Chr(13) & Chr(10)
        getHeader = getHeader &  |Content-Disposition: attachment; filename= | &"D" & Cstr(Right(Rnd(),4)) & |.xls| &Chr(13) & Chr(10)
        getHeader = getHeader  &   "<html xmlns:x=""urn:schemas-microsoft-com:office:excel"">"
        getHeader = getHeader  &   "<head>"
        getHeader = getHeader  &   "<!--[if gte mso 9]><xml>"
        getHeader = getHeader  &   "<x:ExcelWorkbook>"
        getHeader = getHeader  &   "<x:ExcelWorksheets>"
        getHeader = getHeader  &   "<x:ExcelWorksheet>"
        getHeader = getHeader  &   "<x:Name>"& "Export" &"</x:Name>"
        getHeader = getHeader  &   "<x:WorksheetOptions>"
        getHeader = getHeader  &   "<x:Print>"
        getHeader = getHeader  &   "<x:ValidPrinterInfo/>"
        getHeader = getHeader  &   "</x:Print>"
        getHeader = getHeader  &   "</x:WorksheetOptions>"
        getHeader = getHeader  &   "</x:ExcelWorksheet>"
        getHeader = getHeader  &   "</x:ExcelWorksheets>"
        getHeader = getHeader  &   "</x:ExcelWorkbook>"
        getHeader = getHeader  &   "</xml>"
        getHeader = getHeader  &   "<![endif]--> "
        getHeader = getHeader  &   "</head>"
    End Function 

Yes… I know Julian has a great StringBuffer class. I will use it at some point.

Comment Pages

There are 3 Comments to "Gridlines for Printing Excel from a Web Agent"

  • I have been creating a lot of Excel reports using XML via LotusScript. I found the easiest way to figure out an XML equivalent setting is to save as XML an Excel spreadsheet before and after changing a setting. I then compare the differences.

    Also, it looks like adding the following line might be enough for the gridlines to show:

    Similarly, to remove the gridlines, you could add a element.

  • Looks like the XML got stripped out:

    To show the gridlines:

    A “WorksheetOptions” element.

    To remove the gridlines:

    A “DoNotDisplayGridlines” element.

  • tom says:

    That’s a great idea (the saving of spreadsheets in XML to the elements).

    Thanks for the tip!

 

Essentials