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

  • 相关阅读:
    vscode开发环境安装配置-连载【2】-企业级系统开发实战连载系列 -技术栈(vue、element-ui、qt、c++、sqlite)
    nodejs开发环境安装-连载【1】-企业级系统开发实战连载系列 -技术栈(vue、element-ui、qt、c++、sqlite)
    vs 2015 菜单重复的问题解决方法
    ecshop代码详解之init.php
    前端jquery实现点击图片弹出大图层(且滚动鼠标滑轮图片缩放)
    thinkPHP中省市级联下拉列表
    mysql函数date_format统计刷选按年月日统计的数据
    jQuery插件实现select下拉框左右选择_交换内容(multiselect2side)
    php代码生成二维码
    ASP.NET无效的视图
  • 原文地址:https://www.cnblogs.com/cnaspnet/p/4443321.html
Copyright © 2011-2022 走看看