generate Excel file


I have an web app that uses a backend SQL database.
Certain users need to go in and click a button that generates
an application form in Excel format , that is then filled out and
sent somewhere.
How do I generate an Excel doc like this. Do I store the doc online?

Not sure as to how to go about this...
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
Kamal KhaleefaConnect With a Mentor Information Security SpecialistCommented:

in other words you need to export the data you have into excel sheet;right??

if this is the case here is the code:
first add a button to your page and name it cmdExport

Private Sub cmdExport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdExport.Click

            Dim dt As New DataTable


            If dt.Rows.Count = 0 Then
        'show a msg that there is no data to export
                Exit Sub
            End If


            HttpContext.Current.Response.ContentType = "Application/x-msexcel"
            HttpContext.Current.Response.Clear() '
            'add the response headers
            HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=myfile.xls")
            Response.Write("<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />")

            'create our datagrid object
            Dim csvGrid As DataGrid = New DataGrid()
            'set the datasource for datatable
            csvGrid.DataSource = dt  
            'bind the values in our datatable to our grid
            'create our stringwriter object
            Dim StringWriter As System.IO.StringWriter = New System.IO.StringWriter()

            'create our htmltextwriter
            Dim htmlWriter As HtmlTextWriter = New HtmlTextWriter(StringWriter)
            'render the contents of our datagrid to the htmlwriter
            'since the convert to string the value of our stringwriter object.
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8
            '                       //close the connection
            '                       command.Connection.Close();
            'end the http response

        Catch ex As Exception
        End Try

    End Sub

Open in new window

Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.