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位程序。

  • 相关阅读:
    二叉树 Java 实现 前序遍历 中序遍历 后序遍历 层级遍历 获取叶节点 宽度 ,高度,队列实现二叉树遍历 求二叉树的最大距离
    Java:JUnit4使用详解
    Java 常用数据结构对象的实现原理 集合类 List Set Map 哪些线程安全 (美团面试题目)
    JAVA里的布尔运算符-甲骨文面试题
    try catch finally 用法
    Java的JDBC事务详解
    Java开发中JDBC连接数据库代码和步骤
    WebUploader文件图片上传插件的使用
    webuploader解决不能重复上传问题及一些常见问题处理
    HTML5 input file控件使用accept过滤限制的文件类型以及在谷歌下打开很慢的问题
  • 原文地址:https://www.cnblogs.com/cnaspnet/p/4443321.html
Copyright © 2011-2022 走看看