title: Export excel data using Response.Output
body: <p>I have the following code to save for Excel export:</p>
  
  <pre><code>'Export to Excel
          Response.Clear()
          Response.Buffer = True
          Response.AddHeader("content-disposition", "attachment;filename=excelExport.xls")
          Response.Charset = ""
          Response.ContentType = "application/vnd.ms-excel"
  
          Dim sw As New StringWriter()
          Dim hw As New HtmlTextWriter(sw)
  
          Dim grdView = New GridView
  
          grdView.AllowPaging = False
  
          'LOAD DATA
          Dim Sql As String = "SELECT * " &amp; _
               "FROM bobSettings AS bobSettings " &amp; _
                "INNER JOIN bobData AS bobData " &amp; _
               "ON bobSettings.linkTobobData = bobData.linkTobobSettings " &amp; _
               "WHERE linkTobobSettings = '1110450005' "
  
          Dim checkFormName As New SqlCommand(Sql, myCONN)
  
          myCONN.Open()
  
          Dim objCmd As SqlCommand
  
          objCmd = New SqlCommand(Sql, myCONN)
  
          Dim da As New SqlDataAdapter(objCmd)
          Dim ds As New DataSet()
          da.Fill(ds)
  
          grdView.DataSource = ds
          grdView.DataBind()
          myCONN.Close()
          'END LOADING DATA
  
          grdView.DataBind()
          grdView.HeaderRow.Style.Add("background-color", "#FFFFFF")
          grdView.HeaderRow.Cells(0).Style.Add("background-color", "#DFB")
          grdView.HeaderRow.Cells(1).Style.Add("background-color", "#DFB")
          grdView.HeaderRow.Cells(2).Style.Add("background-color", "#DFB")
          grdView.HeaderRow.Cells(3).Style.Add("background-color", "#DFB")
          grdView.HeaderRow.Cells(4).Style.Add("background-color", "#DFB")
          grdView.HeaderRow.Cells(5).Style.Add("background-color", "#DFB")
          grdView.HeaderRow.Cells(6).Style.Add("background-color", "#DFB")
          grdView.HeaderRow.Cells(7).Style.Add("background-color", "#DFB")
          grdView.HeaderRow.Cells(8).Style.Add("background-color", "#DFB")
          grdView.HeaderRow.Cells(9).Style.Add("background-color", "#DFB")
          grdView.HeaderRow.Cells(10).Style.Add("background-color", "#DFB")
  
          For i As Integer = 0 To grdView.Rows.Count - 1
              Dim row As GridViewRow = grdView.Rows(i)
  
              row.BackColor = System.Drawing.Color.White
              row.Attributes.Add("class", "textmode")
  
              If i Mod 2 &lt;&gt; 0 Then
                  row.Cells(0).Style.Add("background-color", "#C2D69B")
                  row.Cells(1).Style.Add("background-color", "#C2D69B")
                  row.Cells(2).Style.Add("background-color", "#C2D69B")
                  row.Cells(3).Style.Add("background-color", "#C2D69B")
                  row.Cells(4).Style.Add("background-color", "#C2D69B")
                  row.Cells(5).Style.Add("background-color", "#C2D69B")
                  row.Cells(6).Style.Add("background-color", "#C2D69B")
                  row.Cells(7).Style.Add("background-color", "#C2D69B")
                  row.Cells(8).Style.Add("background-color", "#C2D69B")
                  row.Cells(9).Style.Add("background-color", "#C2D69B")
                  row.Cells(10).Style.Add("background-color", "#C2D69B")
              End If
          Next
          grdView.RenderControl(hw)
  
          Dim style As String = "&lt;style&gt;.textmode{mso-number-format:\@;}&lt;/style&gt;"
  
          Response.Write(style)
          Response.Output.Write(sw.ToString())
          Response.Flush()
          Response.End()
          ds = Nothing
          da = Nothing
  </code></pre>
  
  <p>And it executes without problems or errors BUT i can not seem to find where it places the file or do it ever pop up a box asking me to save it, etc.</p>
  
  <p>What am i missing?</p>