asp.net – 从互联网上打开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 = 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)将打开一个空白窗口,没有任何警告或消息,说明为何阻止了任何内容,并且没有接受要打开的文件的选项. 我的代码在Intranet站点上运行,我可以访问Windows中的组策略/设置/用户配置. 解决方法解决方案11)打开Excel转到文件选项 2)点击信任中心 – >信任中心设置 3)转到受保护的视图.有3个选项显示全部被点击.取消选中第一个选项 – “为来自Internet的文件启用受保护的视图”.在下面的评论中报告的某些情况下,第一和第二选项都需要取消选中(谢谢@mosheb) 解决方案2 卸载这些Windows更新: > Windows Update KB3115262(Excel 2013)> Windows Update KB3115130(Excel 2010) (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 如何在ASP.NET 5和Visual Studio 2015 CTP中添加常规类lib引
- asp.net-mvc – 为什么调用base.OnActionExecuting(filterC
- asp.net-mvc-3 – 从剃刀视图引用资源文件
- 我应该在ASP.NET MVC中构建我的下一个Web应用程序吗?
- asp.net-mvc – 缓存直到ASP.NET MVC和Entity Framework 4.
- 在asp.net中使用eval(“”)
- iis-7 – 本地语言的布尔值
- asp.net-mvc – 如何在ASP.Net MVC中对自定义ActionFilter进
- asp.net – 将通用模型的子类传递给剃刀视图
- 勾选复选框时,禁用一些ASP.Net验证控件
- 如何使用ASP.NET解析JSON字符串?
- 如何在asp.net中获取服务器/网站的IP地址?
- asp.net – AutoMapper:将集合中的项目值从一个
- asp.net – 如何使IRouteConstraint过滤器路由
- asp.net-mvc – 处理asp.net mvc中的错误和异常
- asp.net-mvc – ModelState.IsValid总是返回fals
- IIS部署的ASP.NET 5 BETA 8站点到IIS会给出HTTP错
- asp.net-mvc-3 – MVC3 Razor使用Html.BeginForm
- asp.net – 任何方式构建Google文档,如PDF文件的
- asp.net-mvc-3 – ASP.NET MVC 3.0 Razor,从任何
