• 手动导出Excel方法


    private void dgJiBingZhenDuanBind()    

    {        

        Response.Clear();

        Response.Charset = "GB2312";

            Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");

            Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。

            Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("柘荣县医院住院病历" + DateTime.Now.ToShortDateString() + ".xls", Encoding.UTF8));         this.EnableViewState = false;

            StringBuilder sbHtml = new StringBuilder();

            sbHtml.Append("<table border='1'>");

            sbHtml.Append("<tr>");

            sbHtml.Append("<td>住院号</td>");

            sbHtml.Append("<td>姓名</td>");

            sbHtml.Append("<td>性别</td>");

            //  sbHtml.Append("<td>床位号</td>");

            sbHtml.Append("<td>出生日期</td>");

            //sbHtml.Append("<td>职业</td>");

            // sbHtml.Append("<td>地址</td>");

            sbHtml.Append("<td>入院时间</td>");

            sbHtml.Append("<td>入院诊断</td>");

            sbHtml.Append("<td>出院时间</td>");

            sbHtml.Append("<td>出院诊断</td>");

            sbHtml.Append("<td>医生</td>");

            sbHtml.Append("</tr>");

            DataTable dt = Session["BingLiChaXun"] as DataTable;

            if (CanShuPanDuan.ShiFouKong(dt, 1))

            {

                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "msg", "<script language='javascript'>yanshitishi('系统提示:打印暂无数据,请先进行查询!','2')</script>");

                return;

            }

            //逐行处理数据

            foreach (DataRow row in dt.Rows)

            {

                sbHtml.Append("<tr>");

                sbHtml.Append("<td>" + row["ZHUYUANHAO"].ToString() + "</td>");

                sbHtml.Append("<td>" + row["XINGMING"].ToString() + "</td>");

                sbHtml.Append("<td>" + row["XINGBIE"].ToString() + "</td>");

                //sbHtml.Append("<td>" + row["chuanghao"].ToString() + "</td>");

                sbHtml.Append("<td>" + row["newnianling"].ToString() + "</td>"); //  杨磊

                //sbHtml.Append("<td>" + row["zhiye"].ToString() + "</td>");

                //sbHtml.Append("<td>" + row["hukoudizhi"].ToString() + "</td>");

                sbHtml.Append("<td>" + row["RUYUANSHIJIAN"].ToString() + "</td>");

                sbHtml.Append("<td>" + row["ruyuanzhenduan1"].ToString() + "</td>");

                sbHtml.Append("<td>" + row["CHUYUANSHIJIAN"].ToString() + " </td>");

                sbHtml.Append("<td>" + row["chuyuanzhenduan1"].ToString() + "</td>");

                sbHtml.Append("<td>" + row["yisheng"].ToString() + "</td>");

                sbHtml.Append("</tr>");

            }

            sbHtml.Append("</table>");

            Response.Write("<meta http-equiv=Content-Type content=text/html;charset=gb2312>");

            Response.Write(sbHtml.ToString());

            Response.End();

        }

  • 相关阅读:
    JS替换字符串多余的空格符
    WebStorm2017.3.4版本 注册码
    使用$.getJSON()需要注意的地方
    45道CSS基础面试题(附答案)
    单机版搭建Hadoop环境图文教程详解
    Ubuntu下安装JDK图文详解
    VMtools安装以及设置
    Ubuntu 12.04中文输入法的安装
    Hadoop 学习之 FAQ
    java ant 命令大全
  • 原文地址:https://www.cnblogs.com/dachuang/p/4165320.html
Copyright © 2020-2023  润新知