• 导出EXCEL


    protected void ButtonExcel_Click1(object sender, EventArgs e)
            {
                List
    <string> userTypes = new List<string>();
                
    if (this.RadioButtonListUserTypes.SelectedValue.Length > 0)
                {
                    userTypes.Add(
    this.RadioButtonListUserTypes.SelectedValue);
                }

                UserStatus userStatus 
    = (UserStatus)Enum.Parse(typeof(UserStatus), this.RadioButtonByUserStatus.SelectedValue);

                
    int recordsCount;
                var userElements 
    = MembershipApi.FindUsers(this.TextBoxQueryByAgencyName.Text, null, userTypes.ToArray(), this.TextBoxQueryByUserName.Text, userStatus, 020out recordsCount);

                StreamReader sr 
    = new StreamReader(Server.MapPath("~/Membership/UserExcel.htm"));
                
    string content = sr.ReadToEnd();
                
    string data = "";

                
    foreach (UserElement dr in userElements)
                {
                    data 
    += "<tr><td>'" + dr.CompanyNames.ToString() + "</td><td>" + dr.CompanyNames.ToString() + "</td><td>" + dr.CompanyNames.ToString() + "</td><td> "
                   
    + dr.RoleNames.ToString() + "</td><td>" + dr.CompanyNames.ToString() + "</td><td>" + dr.CompanyNames.ToString() + "</td><td>" + dr.CompanyNames.ToString() + "</td><td>'" + dr.CompanyNames.ToString() + "</td></tr>";
                }

                content 
    = content.Replace("%data%", data);

                
    string fileName = "EMS_" + DateTime.Now.ToString("yyyyMMddhhmmss"+ ".xls";


                
    //从服务器上保存到本机上
                if (WriteFile(Server.MapPath(@"~/Reports/"), fileName, content))
                {
                    Response.Clear();
                    Response.Buffer 
    = true;
                    Response.AppendHeader(
    "Content-Disposition""attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.GetEncoding("UTF-8")));
                    Response.WriteFile(Server.MapPath(
    @"~/Reports/"+ fileName);
                    Response.Flush();
                    Response.Close();
                }
                
    else
                {
                    ClientScript.RegisterStartupScript(
    this.GetType(), "aa""<script>alert('导出报表失败!');</script>");
                    
    return;
                }
            }
  • 相关阅读:
    路由交换03-----传输层协议
    Linux结构目录
    Linux RedHat 7 配置本地 YUM源
    HUAWEI,H3C 三层交换机 常用命令
    windows操作系统更改 <远程桌面> 端口号
    SpringBoot 2.x (2):请求和传参
    SpringBoot 2.x (1):手动创建项目与自动创建项目
    Eclipse中使用Maven搭建SSM框架
    基于Spring和Mybatis拦截器实现数据库操作读写分离
    WinServer配置MySQL主从同步
  • 原文地址:https://www.cnblogs.com/duwamish/p/1344686.html
Copyright © 2020-2023  润新知