Export to Excel

D

Diego

Hi,
I have a ASP.NET application and i'm interested in reporting in excel
format.

I read a good artile written by Steve C. Orr that gave me info
about exporting to excel.

http://www.aspnetpro.com/NewsletterArticle/2003/09/asp200309so_l/asp200309so_l.asp

Basically the app shows the report in a datagrid and on the OnClick event of
the buton beside the datagrid I use the following code (recomended by Steve)
Response.ContentType = "application/ms-excel"

Response.AddHeader("Content-Disposition", "inline;filename=test.xls")

Which works ok but seems to have a limitation in the number of fields (rows
* columns) in the datagrid table in HTML on the client) that can be
exported. The limitation is around 200 fields.

I get an error message when trying to open the file: pop up window with the
text "Unable to read file" generated by Excel. I've tried to see if the
amount of bytes causes the problem but it's not that cause it exports
correctly a huge single text paragraph.

Is there any way to control this?



Thanks in advance.

Diego.
 
D

Diego

I already founded how to, this is a simple code that exports a web page to
excel, no matter how big is it.
Public Class MSExport

Inherits System.ComponentModel.Component

Public Shared Sub export_to(ByVal mime As String, ByVal filename As
String, ByVal response As HttpResponse, ByVal webform As System.Web.UI.Page)

Dim stringWrite As New System.IO.StringWriter()

'create an htmltextwriter which uses the stringwriter

Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)

response.Clear()

response.Charset = ""

'set the response mime type for excel

response.ContentType = mime

response.AddHeader("Content-Disposition", "inline;filename=" &
filename)

webform.Page.RenderControl(htmlWrite)

response.Write(stringWrite.ToString)

response.End()

End Sub

End Class



The call t the method I use from the HTML web page with the report would be:

MSExport.export_to("application/vnd.ms-excel", "test.xls", Me.Response, Me)

Note that can be easylt adapted to export to Word too.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top