乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > springmvc使用poi导出<em>excel</em>需要什么jar-java excel

springmvc使用poi导出<em>excel</em>需要什么jar-java excel

作者:乔山办公网日期:

返回目录:excel表格制作


java导出Excel需要用到poi的jar包,

// 第一步,创建一个webbook,对应一个Excel文件  
        HSSFWorkbook wb = new HSSFWorkbook();  
        // 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet  
        HSSFSheet sheet = wb.createSheet("学生表一");  
        // 第三步,在sheet中添加表头第0行,注意老版e5a48de588b6e79fa5e98193364本poi对Excel的行数列数有限制short  
        HSSFRow row = sheet.createRow((int) 0);  
        // 第四步,创建单元格,并设置值表头 设置表头居中  
        HSSFCellStyle style = wb.createCellStyle();  
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式  
  
        HSSFCell cell = row.createCell((short) 0);  
        cell.setCellValue("学号");  
        cell.setCellStyle(style);  
        cell = row.createCell((short) 1);  
        cell.setCellValue("姓名");  
        cell.setCellStyle(style);  
        cell = row.createCell((short) 2);  
        cell.setCellValue("年龄");  
        cell.setCellStyle(style);  
        cell = row.createCell((short) 3);  
        cell.setCellValue("生日");  
        cell.setCellStyle(style);  
  
        // 第五步,写入实体数据 实际应用中这些数据从数据库得到,  
        List list = CreateSimpleExcelToDisk.getStudent();  
  
        for (int i = 0; i < list.size(); i++)  
        {  
            row = sheet.createRow((int) i + 1);  
            Student stu = (Student) list.get(i);  
            // 第四步,创建单元格,并设置值  
            row.createCell((short) 0).setCellValue((double) stu.getId());  
            row.createCell((short) 1).setCellValue(stu.getName());  
            row.createCell((short) 2).setCellValue((double) stu.getAge());  
            cell = row.createCell((short) 3);  
            cell.setCellValue(new SimpleDateFormat("yyyy-mm-dd").format(stu  
                    .getBirth()));  
        }  
        // 第六步,将文件存到指定位置  
        try  
        {  
            FileOutputStream fout = new FileOutputStream("E:/students.xls");  
            wb.write(fout);  
            fout.close();  
        }  
        catch (Exception e)  
        {  
            e.printStackTrace();  
        }  
    }



你真真真逗
导入那些jar包的前提是你用了那些web框架呀!!! 然后去开源框架的官网下载demo下的jar包呗 然后导入到你的lib目录下。或者用maven。。

用poi-3.9.jar还有logging-commong.jar log4j.jar

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网