Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 使用Visual Basic将网站Gridview导出到Excel_Asp.net_Excel_Vb.net_Export - Fatal编程技术网

Asp.net 使用Visual Basic将网站Gridview导出到Excel

Asp.net 使用Visual Basic将网站Gridview导出到Excel,asp.net,excel,vb.net,export,Asp.net,Excel,Vb.net,Export,我正在尝试将gridview从网站导出到excel文档中 我必须使用Visual Basic,这是一个令人沮丧的问题,因为我确信如果它是C#,我会把它熏掉 我一直在犯这个错误 ScriptResource.axd?。。。。未捕获错误:Sys.WebForms.PageRequestManagerParserErrorException:无法分析从服务器接收的消息。 在Function.Error$create[as create](ScriptResource.axd? 在PageRequest

我正在尝试将gridview从网站导出到excel文档中

我必须使用Visual Basic,这是一个令人沮丧的问题,因为我确信如果它是C#,我会把它熏掉

我一直在犯这个错误

ScriptResource.axd?。。。。未捕获错误:Sys.WebForms.PageRequestManagerParserErrorException:无法分析从服务器接收的消息。 在Function.Error$create[as create](ScriptResource.axd? 在PageRequestManager$\u createPageRequestManagerParserError[作为\u createPageRequestManagerParserError](ScriptResource.axd

我尝试了几个不同的VB脚本来导出gridview…所有这些都会导致相同的解析错误

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    If Not IsPostBack Then
        Me.BindGrid()
    End If
End Sub

Private Sub BindGrid()
    Dim strConnString As String = ConfigurationManager.ConnectionStrings("RData").ConnectionString
    Using con As New SqlConnection(strConnString)
        Using cmd As New SqlCommand("SELECT vWosearch.TypeofWorkOrder FROM vWOSearch")
            Using sda As New SqlDataAdapter()
                cmd.Connection = con
                sda.SelectCommand = cmd
                Using dt As New DataTable()
                    sda.Fill(dt)
                    wogridviewex.DataSource = dt
                    wogridviewex.DataBind()
                End Using
            End Using
        End Using
    End Using
End Sub

Public Sub Export_Click(ByVal sender As Object, ByVal e As System.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)
            wogridviewex.RenderControl(hw)
            Response.Write(hw)
            Response.Output.Write(hw.ToString())
            Response.Flush()
            HttpContext.Current.ApplicationInstance.CompleteRequest()
        End Using


    End Sub
    Public Overloads Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
    End Sub
我试过这个

Public Sub Export_Click(ByVal sender As Object, ByVal e As System.EventArgs)

    wogridview.DataBind()
    Response.Clear()
    Response.Buffer = True
    Response.AddHeader("Content-Disposition", "attachment; filename=MyExcelFileName.xls")
    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
    Dim writer As New System.IO.StringWriter()
    Dim html As New System.Web.UI.HtmlTextWriter(writer)
    wogridview.GridLines = GridLines.Both
    wogridview.RenderControl(html)
    Response.Write(writer)
    Response.Flush()
    HttpContext.Current.ApplicationInstance.CompleteRequest()
    Response.End()


End Sub
Public Overloads Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
End Sub
ASPx页面中的gridview很简单

<asp:UpdatePanel ID="outerupdatepanel" runat="server">
<ContentTemplate>
<asp:Button ID="ExportWorkOrders" runat="server" Text="Export to Excel" onclick="Export_Click"/>

         <asp:GridView ID="wogridviewex" runat="server" AllowPaging="False" DataSourceID="SD1">  
            <Columns>
                <asp:BoundField DataField="TypeofWorkOrder" HeaderText="Part Code" />
           </Columns>
         </asp:GridView>

    <asp:SqlDataSource ID="sd1" runat="server" ConnectionString='<%$ ConnectionStrings:here%>'
        SelectCommand="blah enter my sql stuff">
</ContentTemplate>
</asp:UpdatePanel>

发生这种情况的原因是我有一个

<asp:UpdatePanel ID="outerupdatepanel" runat="server">
<ContentTemplate>


在顶部和底部,删除ASP:updatePanel可以消除解析错误。只要您从aspx中删除updatePanel,上述三种方法都可以工作。

开始使用专门的库来创建Excel文件,例如。您现在所做的就是创建一个扩展名为.xls的HTML页面。我不会这样做我不认为我需要一个特殊的库来获取网格视图并将其转换为excel。我安装了用于Epplus的nueget,但它们似乎没有任何将girdview导出到excel的VB示例。我发现了大量的C#示例,但我需要VB中的一些功能。用户使用此网格视图所做的另一件事是将其过滤为select一组数据,然后他们想将其导出,老板不希望他们像现在那样复制粘贴到excel中,但我必须处理的唯一示例不是导出Gridview。现在我的头告诉我不要将Gridview导出到excel中,而是将查询结果导出到excel中。我已将Epplus API实现到excel中在我为VB编写了各种API之后,他访问了这个站点,仍然得到了一个解析错误。
<asp:UpdatePanel ID="outerupdatepanel" runat="server">
<ContentTemplate>