zoukankan      html  css  js  c++  java
  • 导出execl

           string filepath = Utils.GetMapPath("/upload/excel/");
                filepath = filepath + fileName + ".xls";
                string tempFilePath = Utils.GetMapPath("/ExcelTemplate/export_comment_excel.xlsx");
    
                DataSet ds = new BLL.Comment().GetList(0, strWhere, "addtime desc");
    
                DataTable exportDT = new DataTable();
                exportDT.Columns.Add("姓名", typeof(string));
                exportDT.Columns.Add("评价等级(星星数)", typeof(int));
                exportDT.Columns.Add("评价内容", typeof(string));
                exportDT.Columns.Add("评价时间", typeof(string));
                exportDT.Columns.Add("状态", typeof(string));
                exportDT.Columns.Add("原因", typeof(string));
    
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        DataRow dr = exportDT.NewRow();
                        dr["姓名"] = ds.Tables[0].Rows[i]["Name"].ToString();
                        dr["评价等级(星星数)"] = ds.Tables[0].Rows[i]["level"].ToString();
                        dr["评价内容"] = ds.Tables[0].Rows[i]["content"].ToString();
                        dr["评价时间"] = ds.Tables[0].Rows[i]["addtime"].ToString();
                        dr["状态"] = GetStatus(ds.Tables[0].Rows[i]["status"].ToString());
                        dr["原因"] = ds.Tables[0].Rows[i]["reason"].ToString();
                        exportDT.Rows.Add(dr);
                    }
                }
    
                Common.ExcelToData.ExportExcel(tempFilePath, filepath, exportDT, "评论信息");
    
            GC.Collect();//行销毁   
                HttpContext.Current.Response.Buffer = true;
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.ContentType = "application/ms-excel";
                HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName + "(" + DateTime.Now.ToString("yyMMddHHmm") + ").xls");
                HttpContext.Current.Response.WriteFile(filepath);
                HttpContext.Current.Response.Flush();
                File.Delete(filepath);
    
                HttpContext.Current.Response.End();
  • 相关阅读:
    Java中String类两种实例化的区别(转)
    Linux内核如何装载和启动一个可执行程序(转)
    CentOS 7 下安装jdk1.8(转)
    MySQL中死锁(转)
    CTF取证方法大汇总,建议收藏!
    实战经验|大神战队都在i春秋教你打CTF
    CTF丨从零开始搭建WEB Docker靶场
    业务逻辑漏洞探索之敏感信息泄露
    实战经验丨业务逻辑漏洞探索之活动类漏洞
    漏洞经验分享丨Java审计之XXE(下)
  • 原文地址:https://www.cnblogs.com/jronny/p/12091344.html
Copyright © 2011-2022 走看看