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);  /*输出*/
                    }
           
            }

  • 相关阅读:
    [CareerCup] 11.6 Search a 2D Matrix 搜索一个二维矩阵
    [CareerCup] 11.5 Search Array with Empty Strings 搜索含有空字符串的数组
    [CareerCup] 11.4 Sort the File 文件排序
    [CareerCup] 11.3 Search in Rotated Sorted Array 在旋转有序矩阵中搜索
    VTK 6.3.0 Qt 5.4 MinGW 4.9.1 Configuration 配置
    [CareerCup] 11.2 Sort Anagrams Array 异位词数组排序
    [CareerCup] 11.1 Merge Arrays 合并数组
    Matlab Delete Row or Col 删除矩阵的行或列
    [CareerCup] 10.7 Simplified Search Engine 简单的搜索引擎
    [LeetCode] Nim Game 尼姆游戏
  • 原文地址:https://www.cnblogs.com/bin521/p/6406119.html
Copyright © 2011-2022 走看看