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

  • 相关阅读:
    linux 查询文件在多个目录里面,只保留一个
    mysql 定时备份
    mysql 赋予权限报错Column count of mysql.user is wrong. Expected 45, found 43. The table is probably corrupted
    Mysql 启动报错Error: page 5 log sequence number 2580579963
    docker 限制日志文件大小和数量
    docker 安装
    MVC3学习第十五章 武林外传大结局
    MVC3学习第十四章 佟掌柜第三弹——MVC3下利用陕北吴旗娃的验证码控件实现验证码功能以及在mvc3下使用编辑器
    MVC3学习第十三章 佟掌柜第二弹——MVC3下利用陕北吴旗娃的分页控件实现数据分页
    MVC3学习第十二章 佟掌柜第一弹----利用MVC3实现用户的注册登录和了解MVC中的分部视图、用户控件
  • 原文地址:https://www.cnblogs.com/cnaspnet/p/4443321.html
Copyright © 2011-2022 走看看