小编Tay*_*own的帖子

从Internet打开excel文件会打开一个空白的Excel窗口

最近,新的Windows更新破坏了将GridView转储到Excel文件以从Internet下载/打开的方法.

我的代码使用StringWriter,HTMLTextWriter和RenderControl从GridView转储到XLS文件.使用以下代码的常用方法来自http://www.aspsnippets.com/Articles/Export-GridView-to-Excel-in-ASPNet-with-Formatting-using-C-and-VBNet.aspx

Protected Sub ExportToExcel(sender As Object, e As EventArgs)
    Response.Clear()
    Response.Buffer = True
    Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.xls")
    Response.Charset = ""
    Response.ContentType = "application/vnd.ms-excel"
    Using sw As New StringWriter()
        Dim hw As New HtmlTextWriter(sw)

        'To Export all pages
        GridView1.AllowPaging = False
        Me.BindGrid()

        GridView1.HeaderRow.BackColor = Color.White
        For Each cell As TableCell In GridView1.HeaderRow.Cells
            cell.BackColor = GridView1.HeaderStyle.BackColor
        Next
        For Each row As GridViewRow In GridView1.Rows
            row.BackColor = Color.White
            For Each cell As TableCell In row.Cells
                If row.RowIndex Mod 2 = 0 Then
                    cell.BackColor …
Run Code Online (Sandbox Code Playgroud)

vb.net asp.net excel intranet

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

asp.net ×1

excel ×1

intranet ×1

vb.net ×1