【问题标题】:Export Gridview to Excel without prompt window将 Gridview 导出到 Excel 没有提示窗口
【发布时间】:2011-07-07 02:53:04
【问题描述】:

我可以将我的gridview导出到excel,但我不想提示一个窗口询问文件名和路径,我该如何禁用它? 另外,如何设置保存文件的路径?

谢谢 乔

以下是我的代码:

Private Sub ExportGridView()

    Dim filename As String
    filename = ddlMonth.SelectedValue & "-" & ddlYear.SelectedValue

    Dim attachment As String = "attachment; filename=" & filename & ".xls"

    Response.ClearContent()
    Response.Buffer = True
    Response.Charset = "UTF-8"        
    Response.AddHeader("content-disposition", attachment)
    Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8")
    Me.EnableViewState = False
    Response.ContentType = "application/ms-excel"

    Dim sw As New StringWriter()
    Dim htw As New HtmlTextWriter(sw)

    'Turn off the paging for export
    Gridview1.DataSource = Session("dt")
    Gridview1.AllowPaging = False
    Gridview1.DataBind()

    GridView1.RenderControl(htw)
    Response.Write(sw.ToString())
    Response.[End]()

    'Turn on the paging after export
    Gridview1.DataSource = Session("dt")
    Gridview1.AllowPaging = True
    Gridview1.DataBind()

End Sub

【问题讨论】:

    标签: asp.net excel gridview export


    【解决方案1】:

    //声明 //并在后面的代码中。 protected String MyMethodCall() { return "Test Value"; }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-25
      • 2013-12-02
      • 2014-12-20
      • 1970-01-01
      相关资源
      最近更新 更多