Link to home
Start Free TrialLog in
Avatar of BenJen
BenJen

asked on

Exporting to Excel MAC/Safari Issue - Blank Document

Hello,

I am having an issue getting  report HTML to export to excel on MAC/Safari.

The export works perfectly fine on a PC, our client however is largely MAC based and gets a blank excel when trying to export.

Below is the code being used to export:

        
        Dim str As String = ""
        Dim path As String = Server.MapPath("css/global.css")
        Dim CssString As String = ""

        CssString = File.ReadAllText(path)

        Dim sw As New StringWriter()
        Dim htmlWriter As New HtmlTextWriter(sw)
        OutputRows.RenderControl(htmlWriter)

        Dim html As String = "<html><head><style> " + CssString + " </style></head><body>"   + PrintHeader + "<div align=""center""> " + str + "</div><br/><br/><div align=""center"">" + PrintCopyright + "</div></body></html>"


        Response.Clear()
        Response.ContentType = "application/vnd.ms-excel"
        Response.AddHeader("content-disposition", "attachment; filename= Benchmarking Toolkit Report " + Date.Now().ToShortDateString + ".xls")
        Response.Write(html)
        Response.End()

Open in new window



As stated this exports fine on a PC but not on MAC or Safari, they get only get a blank excel.
The report generates less than 2000 rows in excel.


Help is much appreciated,

Thanks
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Change the html so you are just building a table and not div's.  I do the same thing and never had an issue. If you just need data in excel and not formatted, then create a csv file instead. All you need to do is add a comma between the fields and enclose in quotes.  Add a vbcrlf at the end of the row.
ASKER CERTIFIED SOLUTION
Avatar of BenJen
BenJen

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BenJen
BenJen

ASKER

I found the issue and corrected myself.