zoukankan      html  css  js  c++  java
  • 将数据库中的表以excel或doc形式保存到客户端

    DataTable dt = SQL.OperateSQL.GetDatatable();
            if ( dt != null)
            {
                System.Web.UI.WebControls.DataGrid dgExport = null;
                System.Web.HttpContext curContext = System.Web.HttpContext.Current;
                System.IO.StringWriter strWriter = null;
                System.Web.UI.HtmlTextWriter htmlWriter = null;

                //curContext.Response.ContentType="application/vnd.ms-excel";
                curContext.Response.ContentType = "application/msword";
                curContext.Response.ContentEncoding = System.Text.Encoding.UTF8;
                curContext.Response.Charset = "";

                strWriter = new System.IO.StringWriter();
                htmlWriter = new HtmlTextWriter(strWriter);

                dgExport = new DataGrid();
                dgExport.DataSource = dt.DefaultView;
                dgExport.AllowPaging = false;
                dgExport.DataBind();

                dgExport.RenderControl(htmlWriter);
                curContext.Response.Write(strWriter.ToString());
                curContext.Response.End();
            }

    首先从数据库中映射至内存中的一张数据表,然后通过浏览器以不同形式的流输出。

  • 相关阅读:
    字的传送
    mov 寄存器,段寄存器
    c语言中利用三维数组计算成绩总分数
    python中break语句
    c语言中求课程总分、平均分。学生总分及平均分
    python中assert语句
    python中random模块引入随机数
    python中实现列表的倒序排列
    c语言中求两个矩阵的乘积
    python的严格缩进可以避免else悬挂
  • 原文地址:https://www.cnblogs.com/xinzhuangzi/p/4100653.html
Copyright © 2011-2022 走看看