.NET 导出到 Excel - IE 中的错误?
我正在尝试将报告导出到 vb.net 中的 Excel 中。
在 Chrome 和 FF 中一切正常,但是当我在 IE 中执行此操作时,活动目录登录弹出窗口不断出现。
如果我取消它(比如 4-5 次),文件保存得很好...为什么它会弹出>有办法解决吗?
请参阅下面的我的代码:
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这很可能是 IE8/9 中的安全问题。尝试将主机添加到 IE 选项的“安全”选项卡上的“受信任的站点”。您还可以尝试在尝试下载电子表格时按住左 Shift 键。
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.
通过将数据逐个循环地写入 Excel 来修复此问题。
it got fixed by writing out the data to excel, cell by cell in a loop.