从 Internet 打开 excel 个文件会打开一个空白 excel window
Opening excel files from the internet opens a blank excel window
一种从 Internet 将 GridView 转储到 Excel 文件到 download/open 的方法最近被新的 Windows 更新破坏了。
我的代码使用 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 = GridView1.AlternatingRowStyle.BackColor
Else
cell.BackColor = GridView1.RowStyle.BackColor
End If
cell.CssClass = "textmode"
Next
Next
GridView1.RenderControl(hw)
'style to format numbers to string
Dim style As String = "<style> .textmode { } </style>"
Response.Write(style)
Response.Output.Write(sw.ToString())
Response.Flush()
Response.[End]()
End Using
End Sub
Public Overrides Sub VerifyRenderingInServerForm(control As Control)
' Verifies that the control is rendered
End Sub
Excel (2013) 将打开一个空白 window,没有关于任何内容被阻止的原因的警告或消息,也没有接受文件打开的选项。
我的代码是 运行 在内部网站上,我确实可以访问 Windows 中的组策略/设置/用户配置。
解决方案 1
1) 打开 Excel 转到文件选项
2) 点击信任中心 -> 信任中心设置
3) 转到受保护的视图。有3个选项显示都被点击了。取消选中显示为 -- "Enable Protected View for files originating from the Internet" 的第一个选项。在某些情况下,正如下面评论中所报告的,第一个和第二个选项都需要取消选中(感谢@mosheb)
解决方案 2
卸载这些 Windows 更新:
- Windows 更新 KB3115262(Excel 2013)
- Windows 更新 KB3115130(Excel 2010)
解决方案 3
- 进入文件的属性(R 单击 - 属性)
- 点击'Unblock'
- 点击'Apply'
不幸的是,更改安全选项不是一个选项,但事实证明,如果您导出为 CSV 而不是 XLS,则文件将在 Excel 中打开,忽略信任中心内容。
我们使用的是经典 ASP,因此我们将页面从导出 HTML table 格式更改为 CSV,并将页眉和内容类型更改为:
Response.AddHeader "content-disposition", "attachment; filename=search_results.csv"
Response.ContentType = "text/csv"
换行符:Response.Write (chr(10))
只是想我会提到还有第三种解决方案:
将生成 .xls 的站点添加到您的可信站点列表中。我不得不通过 GPO 添加大约十几个网站,因为我们的 CIO 拒绝回滚 KB... =(
有同样的问题。更新阻止了此导出到 excel activity 并且并非我的全球用户都有权取消阻止。它影响 2010 和 2013 .xls。我认为它是为了解决内容类型。您是否尝试过将内容类型从 application/vnd.ms-excel 切换到 application/vnd.openxmlformats-officedocument.spreadsheetml.sheet 并改用 xlsx?
尝试执行以下操作:
将
替换为 "attachment"
Response.AddHeader("content-disposition","attachment;filename=GridViewExport.xls")
和"inline"
Response.AddHeader("content-disposition","inline;filename=GridViewExport.xls")
可能会有帮助!
Content-Disposition:What are the differences between "inline" and "attachment"?
根据 ,如果 excel 即使在将网站添加到您的 Trusted Sites 列表后仍以空白打开,您可以 try/suggest下面解决方法。
打开 excel 工作簿,即使它是灰色的 out/blank,然后单击 excel 中的“查看”选项卡,然后单击在 'full screen/maximize screen icon' 上,如下面的屏幕截图所示。这对我有用。
一种从 Internet 将 GridView 转储到 Excel 文件到 download/open 的方法最近被新的 Windows 更新破坏了。
我的代码使用 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 = GridView1.AlternatingRowStyle.BackColor
Else
cell.BackColor = GridView1.RowStyle.BackColor
End If
cell.CssClass = "textmode"
Next
Next
GridView1.RenderControl(hw)
'style to format numbers to string
Dim style As String = "<style> .textmode { } </style>"
Response.Write(style)
Response.Output.Write(sw.ToString())
Response.Flush()
Response.[End]()
End Using
End Sub
Public Overrides Sub VerifyRenderingInServerForm(control As Control)
' Verifies that the control is rendered
End Sub
Excel (2013) 将打开一个空白 window,没有关于任何内容被阻止的原因的警告或消息,也没有接受文件打开的选项。
我的代码是 运行 在内部网站上,我确实可以访问 Windows 中的组策略/设置/用户配置。
解决方案 1
1) 打开 Excel 转到文件选项
2) 点击信任中心 -> 信任中心设置
3) 转到受保护的视图。有3个选项显示都被点击了。取消选中显示为 -- "Enable Protected View for files originating from the Internet" 的第一个选项。在某些情况下,正如下面评论中所报告的,第一个和第二个选项都需要取消选中(感谢@mosheb)
解决方案 2
卸载这些 Windows 更新:
- Windows 更新 KB3115262(Excel 2013)
- Windows 更新 KB3115130(Excel 2010)
解决方案 3
- 进入文件的属性(R 单击 - 属性)
- 点击'Unblock'
- 点击'Apply'
不幸的是,更改安全选项不是一个选项,但事实证明,如果您导出为 CSV 而不是 XLS,则文件将在 Excel 中打开,忽略信任中心内容。
我们使用的是经典 ASP,因此我们将页面从导出 HTML table 格式更改为 CSV,并将页眉和内容类型更改为:
Response.AddHeader "content-disposition", "attachment; filename=search_results.csv"
Response.ContentType = "text/csv"
换行符:Response.Write (chr(10))
只是想我会提到还有第三种解决方案:
将生成 .xls 的站点添加到您的可信站点列表中。我不得不通过 GPO 添加大约十几个网站,因为我们的 CIO 拒绝回滚 KB... =(
有同样的问题。更新阻止了此导出到 excel activity 并且并非我的全球用户都有权取消阻止。它影响 2010 和 2013 .xls。我认为它是为了解决内容类型。您是否尝试过将内容类型从 application/vnd.ms-excel 切换到 application/vnd.openxmlformats-officedocument.spreadsheetml.sheet 并改用 xlsx?
尝试执行以下操作:
将
替换为 "attachment"Response.AddHeader("content-disposition","attachment;filename=GridViewExport.xls")
和"inline"
Response.AddHeader("content-disposition","inline;filename=GridViewExport.xls")
可能会有帮助!
Content-Disposition:What are the differences between "inline" and "attachment"?
根据
打开 excel 工作簿,即使它是灰色的 out/blank,然后单击 excel 中的“查看”选项卡,然后单击在 'full screen/maximize screen icon' 上,如下面的屏幕截图所示。这对我有用。