.NET 导出到 Excel - IE 中的错误?

发布于 2024-11-17 16:59:43 字数 1259 浏览 2 评论 0原文

我正在尝试将报告导出到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜灵血窟げ 2024-11-24 16:59:43

这很可能是 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.

少年亿悲伤 2024-11-24 16:59:43

通过将数据逐个循环地写入 Excel 来修复此问题。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文