• 今天刚用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);  /*输出*/
                    }
           
            }

  • 相关阅读:
    sql中触发器的使用
    sql中优化查询
    sql中case when语句的使用
    CSRF学习小结
    javascript正则表达式笔记
    elementUI单选框获取值
    elementUI内置过渡(折叠)
    elementUI内置缩放过渡(缩放)
    elementUi内置过渡动画(淡入)
    创建koa2项目
  • 原文地址:https://www.cnblogs.com/bin521/p/6406119.html
Copyright © 2020-2023  润新知