1

In my function I have the following instructions:

grid.DataSource = dt
        grid.DataBind()

        Response.Clear()
        Response.AddHeader("content-disposition", "attachment; filename=Soste.xls")
        Response.AddHeader("Content-Type", "application/Excel")
        Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
        Response.Charset = ""
        Dim stringWrite As System.IO.StringWriter = New System.IO.StringWriter
        Dim htmlWrite As New HtmlTextWriter(stringWrite)
        grid.RenderControl(htmlWrite)

        Dim html As String = stringWrite.ToString()
        Dim pattern As String = "(\p{Sc})?"
        Dim rgx As New System.Text.RegularExpressions.Regex(pattern)
        html = rgx.Replace(html, "")
        Response.Write(html)
        HttpContext.Current.Response.[End]()

Where grid is a datagrid where I post the data to export.

On the PC it's all right, but when I try to export data to a tablet (android or apple), the file does not open.

I ask: you can do it open even on the mobile?

Many thanks to the response.

Dave Pate
  • 39
  • 1
  • 6
  • Can you upload a small sample of the resulting "Soste.xls" file to a site like [wikisend.com](http://wikisend.com/) and then post the link in a comment here so we can see just what sort of file your code is producing? – Gord Thompson Jan 23 '15 at 12:40
  • http://wikisend.com/download/900780/Soste (1).xls – Dave Pate Jan 23 '15 at 13:34

1 Answers1

0

One likely explanation for your issue is that your code does not actually create a real .xls file. Instead, it creates a text file containing an HTML table and gives the file an .xls extension:

ScreenShot.png

Excel is able to open "fake" .xls files like this (another example would be .csv files that have been renamed to .xls), but the file viewers/editors on other platforms may not be as accommodating.

If you really want to produce an .xls file then you should use a library that creates an actual .xls file. There are some suggestions in another question here:

Create Excel (.XLS and .XLSX) file from C#

Community
  • 1
  • 1
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418