Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

exporting web report to excel or csv file

Status
Not open for further replies.

Shift838

IS-IT--Management
Jan 27, 2003
987
0
0
US
Is it possible when you run a report off the web and it displays on the page that we can put a button to export the report to an excel document or csv file? I want it to be able to pull up a window for the user to browse to on their local machine. I am not sure if this is possible but would like it to be.

1. Users chooses report to run and executes report
2. Report is generated on the page
3. Button to allow users to export report to excel or csv file format and save to their local machine at a location they specify

Any help would be great.
 
Yes - it's fairly straight forward. I'm assuming that the report you are creating now is just HTML (i.e a datagrid or something similar)?

If so, then you just use the RenderCotrol method to export the datagrid and change the ContentType on the page.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I believe this is what ca8msm is suggesting
Code:
 Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            Response.Clear()
            Response.Buffer = True
            Response.ContentType = "application/vnd.ms-excel"
            Response.Charset = ""
            Me.EnableViewState = False
            Dim tw As New System.IO.StringWriter
            Dim hw As New System.Web.UI.HtmlTextWriter(tw)
            DataGrid1.RenderControl(hw)
            Response.Write(tw.ToString())
            Response.End()
        End Sub
I am pretty sure I got this from TT.
Marty
 
yes it is currently just showing it in HTML on the page.
 
Right, it will show the HTML, but it should be in excel format (If the client machine has Excel or the Excel viewer installed, that is. The brower will display a few Excel toolbars, etc. but the content will look largely the same.) They'll have to save it off as if they were saving a webpage, it will just save in .xls format, not html. I used to put conditional blocks around anything I wouldn't want in the xsl file (nav, text, etc.) so when they click the "export to excel" button, it would set the content type to "application/vnd.ms-excel" and only return the tabular data I wanted in the spreadsheet.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top