开发者

.NET Export to Excel - bug in IE?

开发者 https://www.devze.com 2023-03-16 04:03 出处:网络
I am trying to export a report into excel in vb.net. everything works fine in Chrome开发者_运维百科 and FF, but when i do it in IE, the active directory login pop up keeps coming up.

I am trying to export a report into excel in vb.net.

everything works fine in Chrome开发者_运维百科 and FF, but when i do it in IE, the active directory login pop up keeps coming up.

if i cancel it (like 4-5 times) the files saves just fine... why is it popping up> is there a way around it?

please see my code below:

 Protected Sub lnkExport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkExport.Click
        Dim ds As DataSet = cSource.FindSources(Session("uid"), True, txtID.Text )

        Dim response As HttpResponse = HttpContext.Current.Response
        Dim filename As String = "AASD"
        ' first let's clean up the response.object
        response.Clear()
        response.Charset = ""

        ' set the response mime type for excel
        response.ContentType = "application/vnd.ms-excel"
        response.AddHeader("Content-Disposition", "attachment;filename=""" & filename & """")

        ' create a string writer
        Using sw As New StringWriter()
            Using htw As New HtmlTextWriter(sw)
                ' instantiate a datagrid
                Dim dg As New DataGrid()
                dg.DataSource = ds.Tables(0)
                dg.DataBind()
                dg.RenderControl(htw)
                response.Write(sw.ToString())
                response.[End]()
            End Using
        End Using
    End Sub


It's most likely a security issue in IE8/9. Try adding the host to the "Trusted sites" on the Security tab of IE Options. You can also try holding down your left shift key while trying to download the spreadsheet.


it got fixed by writing out the data to excel, cell by cell in a loop.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号