博客
关于我
Excel 导出
阅读量:801 次
发布时间:2023-04-17

本文共 1517 字,大约阅读时间需要 5 分钟。

在一个典型的ASP.NET web应用中,我们可以通过以下步骤实现用户认证和数据处理功能。以下是基于代码的详细说明:

  • 用户认证
    通过从客户端cookie中获取用户信息,验证管理员身份。具体实现如下:
  • admin = Context.Request.Cookies["user"].Values["username"].ToString();
    1. 数据处理
      创建一个hashtable,用于存储传输的参数信息。添加必要的键值对,确保数据能够正确传递:
    2. Hashtable hash = new Hashtable();hash.Add("p2", admin);hash.Add("p_state", 2);
      1. 业务逻辑处理
        调用BLL层的SelectAll_state方法,传递hashtable参数,获取数据集。虽然代码中未直接调用,但逻辑上需要确保BLL方法能够正确处理传递的参数:
      2. DataSet ds = Bll.ProjectInfoBll.SelectAll_state(hash) as DataSet;
        1. 数据绑定
          将获取到的数据集绑定到Repeater控件中,确保控件能够正确显示数据:
        2. Repeater1.DataSource = Bll.ProjectInfoBll.SelectAll_state(hash);this.Repeater1.DataBind();
          1. 文件生成
            根据当前时间生成唯一的文件名,并通过HttpResponse对象将数据写入Excel文件。以下是详细的实现步骤:
          2. string strnum = DateTime.Now.ToString("F");// 生成Excel文件HttpResponse response = Page.Response;response.Clear();response.Buffer = true;response.Charset = "utf-8";// 设置文件编码和字符集,确保文件正确显示response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");response.ContentType = "application/ms-excel";response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(strnum, System.Text.Encoding.UTF8) + ".xls");
            1. 多语言支持
              为了支持简体中文环境,建议在输出流中设置相应的文化信息:
            2. System.Globalization.CultureInfo myCI = new System.Globalization.CultureInfo("ZH-CN", true);System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCI);System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);Repeater1.RenderControl(oHtmlTextWriter);response.Write(oStringWriter.ToString());

              通过以上步骤,我们可以实现用户认证、数据处理、Excel文件导出等功能,确保程序逻辑清晰,数据传输准确。

    转载地址:http://qmgfk.baihongyu.com/

    你可能感兴趣的文章
    MySQL Error Handling in Stored Procedures---转载
    查看>>
    MVC 区域功能
    查看>>
    MySQL FEDERATED 提示
    查看>>
    mysql generic安装_MySQL 5.6 Generic Binary安装与配置_MySQL
    查看>>
    Mysql group by
    查看>>
    MySQL I 有福啦,窗口函数大大提高了取数的效率!
    查看>>
    mysql id自动增长 初始值 Mysql重置auto_increment初始值
    查看>>
    MySQL in 太多过慢的 3 种解决方案
    查看>>
    MySQL InnoDB 三大文件日志,看完秒懂
    查看>>
    Mysql InnoDB 数据更新导致锁表
    查看>>
    Mysql Innodb 锁机制
    查看>>
    MySQL InnoDB中意向锁的作用及原理探
    查看>>
    MySQL InnoDB事务隔离级别与锁机制深入解析
    查看>>
    Mysql InnoDB存储引擎 —— 数据页
    查看>>
    Mysql InnoDB存储引擎中的checkpoint技术
    查看>>
    Mysql InnoDB存储引擎中缓冲池Buffer Pool、Redo Log、Bin Log、Undo Log、Channge Buffer
    查看>>
    MySQL InnoDB引擎的锁机制详解
    查看>>
    Mysql INNODB引擎行锁的3种算法 Record Lock Next-Key Lock Grap Lock
    查看>>
    mysql InnoDB数据存储引擎 的B+树索引原理
    查看>>
    mysql innodb通过使用mvcc来实现可重复读
    查看>>