工具——excel导出

    xiaoxiao2021-03-25  114

    创建前台table表格

    将数据绑定到前台页面

    protected void Button4_Click(object sender, EventArgs e) { dc.Visible = true;//dc 前台div #region 查询条件 DataTable dt = code.GetTable("select * from TT_PreSelection "); #endregion if (dt.Rows.Count > 200) { MessageBox.show(this, "当前数据量超过200条,请筛选后导出!", ""); } else { dtA = dt; Export("application/ms-excel", "excel导出.xls"); dc.Visible = false; } }

    将前台数据输出到表格

    private void Export(string FileType, string FileName) { Response.Charset = "GB2312"; Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); Response.Write("<meta http-equiv=Content-Type content=\"text/html; charset=GB2312\">"); Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString()); Response.ContentType = FileType; this.EnableViewState = false; StringWriter tw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(tw); dc.RenderControl(hw); Response.Write(tw.ToString()); Response.End(); }
    转载请注明原文地址: https://ju.6miu.com/read-12151.html

    最新回复(0)