zoukankan      html  css  js  c++  java
  • 今天刚用asp.net做的导出Eecel

    protected void daochu_Click(object sender, EventArgs e)
            {
                    string hql = "select * from Car";
                    List<Vehicle> list = GetVehicle(hql.ToString()); /*获得数据源*/
                    string filename = Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath.ToString() + "\Template" + "\Vehicle.xls");  /*获得文件路劲*/
                 
          /*不过我的导出Excel文件路劲是写死的,这是不好的地方*/
                    HSSFWorkbook work = new HSSFWorkbook();    /*创建工作薄*/
                    ISheet sheet = work.CreateSheet("第一页");  /*创建表*/
                    IRow row = sheet.CreateRow(0);   /*创建行*/
                    row.CreateCell(0, CellType.String).SetCellValue("管辖机构");    /*创建列*/
                    row.CreateCell(1, CellType.String).SetCellValue("号牌种类");
                    row.CreateCell(2, CellType.String).SetCellValue("号牌号码");
                    row.CreateCell(3, CellType.String).SetCellValue("车辆类型");
                    row.CreateCell(4, CellType.String).SetCellValue("使用性质");
                    row.CreateCell(5, CellType.String).SetCellValue("所有人");
                    row.CreateCell(6, CellType.String).SetCellValue("初次登记日期");
                    row.CreateCell(7, CellType.String).SetCellValue("强制报废期止");
                    row.CreateCell(8, CellType.String).SetCellValue("有效期止");
                    row.CreateCell(9, CellType.String).SetCellValue("车辆状态");
                    for (int i = 0; i < list.Count; i++)
                    {
                        sheet.AutoSizeColumn(i);  /*列的自适应*/
                        IRow rows = sheet.CreateRow(i + 1);   /*给列赋值*/
                        rows.CreateCell(0, CellType.String).SetCellValue(list[i].GLBM);
                        rows.CreateCell(1, CellType.String).SetCellValue(list[i].HPZL);
                        rows.CreateCell(2, CellType.String).SetCellValue(list[i].HPHM);
                        rows.CreateCell(3, CellType.String).SetCellValue(list[i].CLLX);
                        rows.CreateCell(4, CellType.String).SetCellValue(list[i].SYXZ);
                        rows.CreateCell(5, CellType.String).SetCellValue(list[i].SYR);
                        rows.CreateCell(6, CellType.String).SetCellValue("'" + Convert.ToDateTime(list[i].CCDJRQ).ToString("yyyy-MM-dd"));
                        rows.CreateCell(7, CellType.String).SetCellValue("'" + Convert.ToDateTime(list[i].QZBFQZ).ToString("yyyy-MM-dd"));
                        rows.CreateCell(8, CellType.String).SetCellValue("'" + Convert.ToDateTime(list[i].YXQZ).ToString("yyyy-MM-dd"));
                        rows.CreateCell(9, CellType.String).SetCellValue(list[i].ZT);
                    }
                    using (FileStream stream = new FileStream(filename, FileMode.Open))
                    {
                        work.Write(stream);  /*输出*/
                    }
           
            }

  • 相关阅读:
    02 . Vue入门基础之条件渲染,列表渲染,事件处理器,表单控件绑定
    iptables防火墙简介,原理,规则编写,做网络防火墙,常见案例
    Go之发送钉钉和邮箱
    Jumpserver简介,部署及使用
    01 . Go语言实现SSH远程终端及WebSocket
    KVM简介,安装及常见使用,维护详解
    05 . Gin+Vue开发一个线上外卖应用(Session集成及修改用户头像到Fastdfs)
    04 . Gin+Vue开发一个线上外卖应用(用户名密码和图形验证码)
    03 . Gin+Vue开发一个线上外卖应用(用户数据创建,插入,跨域处理)
    02 . Go之Gin+Vue开发一个线上外卖应用(集成第三方发送短信和xorm生成存储数据库表)
  • 原文地址:https://www.cnblogs.com/bin521/p/6406119.html
Copyright © 2011-2022 走看看