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

  • 相关阅读:
    2017ecjtu-summer training #4 CodeForces 731C
    HDU 1232 并查集
    2017ecjtu-summer training #3 POJ3264
    2017ecjtu-summer training #4 UESTC 30
    斑羚飞渡 贪心
    Codeforces Round #565 (Div. 3) D. Recover it!
    P3398 仓鼠找sugar lca
    P3146 [USACO16OPEN]248 dp
    P1955 [NOI2015]程序自动分析 离散化
    P2949 [USACO09OPEN]工作调度Work Scheduling 贪心
  • 原文地址:https://www.cnblogs.com/bin521/p/6406119.html
Copyright © 2011-2022 走看看