从互联网打开excel文件打开一个空白的excel窗口 [英] Opening excel files from the internet opens a blank excel window

查看:177
本文介绍了从互联网打开excel文件打开一个空白的excel窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,新的Windows更新程序将GridView转储到Excel文件以从Internet下载/打开的方法。



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

 受保护的子ExportToExcel(发件人作为对象,作为EventArgs)
Response.Clear()
Response.Buffer = True
Response.AddHeader(content-disposition,attachment; filename = GridViewExport.xls)
Response.Charset =
Response.ContentType =application / vnd.ms -excel
使用sw作为新的StringWriter()
Dim hw作为新的HtmlTextWriter(sw)

'导出所有页面
GridView1.AllowPaging = False
Me.BindGrid()

GridView1.HeaderRow.BackColor = Color.White
对于每个单元格作为TableCell在GridView1.HeaderRow.Cells
cell.BackColor = GridVie w1.HeaderStyle.BackColor
下一个
对于每一行作为GridViewRow在GridView1.Rows
row.BackColor = Color.White
对于每个单元格作为TableCell在row.Cells
如果row.RowIndex Mod 2 = 0然后
cell.BackColor = GridView1.AlternatingRowStyle.BackColor
Else
cell.BackColor = GridView1.RowStyle.BackColor
End If
cell.CssClass =textmode
下一个
下一个

GridView1.RenderControl(hw)
'将数字格式化为字符串的样式
Dim style As String =< style> .textmode {}< / style>
Response.Write(style)
Response.Output.Write(sw.ToString())
Response.Flush()
响应。$($)
结束使用
End Sub

公共覆盖Sub VerifyRenderingInServerForm(控件作为控件)
'验证控件是否呈现
End Sub

Excel(2013)将打开一个空白的窗口,没有警告或消息为什么任何东西被阻止,没有选择接受文件打开。



我的代码是在内部网站上运行的,我可以访问组策略/设置/用户

解决方案

解决方案1 ​​



1)打开Excel转到文件选项



2)单击信任中心 - >信任中心设置



3)转到保护视图,显示所有被点击的3个选项,取消选中第一个选项 - - 启用来自Internet的文件的受保护视图。在某些情况下,如下面的评论所述,第一和第二个选项都需要取消选中(感谢@mosheb)



解决方案2



卸载这些Windows更新:




  • Windows Update KB3115262(Excel 2013)

  • Windows Update KB3115130(Excel 2010)


A method in dumping a GridView to an Excel file to download/open from the internet was recently broken with new Windows Updates.

My code dumps from a GridView to an XLS file using StringWriter, HTMLTextWriter and RenderControl. A common approach using the following code from 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) will open to a blank window, with no warning or message as to why anything was blocked, and without option to accept the file to open.

My code is run on an intranet site, and I do have access to group policies / settings / user configurations in Windows.

解决方案

Solution 1

1) Open Excel Go to File Options

2) Click Trust Center -> Trust Center Settings

3) Go to Protected View. there are 3 options that show that were all clicked. Uncheck the first option that reads -- "Enable Protected View for files originating from the Internet". In some cases as reported in the comments below both the 1st and 2nd options need to be unchecked (Thanks @mosheb)

Solution 2

Uninstall these Windows Updates:

  • Windows Update KB3115262 (Excel 2013)
  • Windows Update KB3115130 (Excel 2010)

这篇关于从互联网打开excel文件打开一个空白的excel窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆