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();
            }

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

  • 相关阅读:
    [机器学习实战]K-近邻算法
    [机器学习Lesson3] 梯度下降算法
    [机器学习Lesson 2]代价函数之线性回归算法
    [机器学习Lesson 1] 机器学习简介
    Flume
    Kafka基础入门
    打造MacOS版“XShell”
    你好,智哥(摘自微信公众号“野兔故事会”)
    打印小册子
    php--strlen()与mb_strlen的作用与区别
  • 原文地址:https://www.cnblogs.com/xinzhuangzi/p/4100653.html
Copyright © 2011-2022 走看看