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

     public static void ChangeExcel(string strcodecom, string stryear, string strmonther, string strdays, string strtype, string struserid)
            {
                string Template = HttpContext.Current.Request.MapPath("~/template/listexcel.xls");
                string FileTemp = HttpContext.Current.Request.MapPath("~/template/" + System.Guid.NewGuid().ToString("N").ToUpper()) + ".xls";
                File.Copy(Template, FileTemp);
                string ConString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Extended Properties=Excel 8.0;" + "Data Source=" + FileTemp;
                string SentenceExcel = String.Format("SELECT * FROM [{0}$]""Sheet1");
                OleDbDataAdapter AdapterClass = new OleDbDataAdapter(SentenceExcel, ConString);
                OleDbCommandBuilder CommandBuilderClass = new OleDbCommandBuilder(AdapterClass);
                CommandBuilderClass.QuotePrefix = "[";
                CommandBuilderClass.QuoteSuffix = "]";
                DataSet DataSetClass = new DataSet();
                AdapterClass.Fill(DataSetClass, "TableName");
                DataTable exceldt = DataSetClass.Tables[0];

                WebClass.CodeList tmp = new WebClass.CodeList();
                List <Models.CodeInfo> list= tmp.CodeListExcel(strcodecom, stryear, strmonther, strdays, strtype, struserid);

                if (list.Count == 0)
                {
                    HttpContext.Current.Response.Write("没记录");
                    HttpContext.Current.Response.Flush();
                    HttpContext.Current.Response.End();
                }
                foreach (Models.CodeInfo info in list)
                {
                    DataRow NewRow = exceldt.NewRow();
                    NewRow["条码"] = info.Codename;
                    NewRow["录入者"] = info.Username;
                    NewRow["操作时间"] = info.Stime;

                    exceldt.Rows.Add(NewRow);
                }
                DataTable DataTableChange = exceldt.GetChanges();
                AdapterClass.Update(DataTableChange);
                //输出文件
                HttpResponse Response = HttpContext.Current.Response;
                Response.AppendHeader("Content-Disposition""attachment;filename=" + HttpUtility.UrlEncode("ListCodeExcel") + ".xls");
                Response.ContentType = "application/ms-excel";
                Response.WriteFile(FileTemp);
                Response.Flush();
                File.Delete(FileTemp);
            }

    II7.5要改兼容32位程序。

  • 相关阅读:
    遍历mac系统访达文件时候要注意了
    python r+ 是追加写
    Linux如何给一个python被挂起进程传递命令?
    nohup后台挂起
    树莓派建站全过程
    wechat robot
    廖雪峰笔记(转网络专题)
    【转】 前端笔记之JavaScript(十一)event&amp;BOM&amp;鼠标/盒子位置&amp;拖拽/滚轮
    【转】 前端笔记之JavaScript(十)深入JavaScript节点&amp;DOM&amp;事件
    【转】 前端笔记之JavaScript(九)定时器&amp;JSON&amp;同步异步/回调函数&amp;函数节流&amp;call/apply
  • 原文地址:https://www.cnblogs.com/cnaspnet/p/4443321.html
Copyright © 2011-2022 走看看