POI导入Excel

public class OutPutExcelUtil {

public static void outputExcel(List<ResumeInfoEntity> list)throws Exception{
int size=list.size();//拿到集合大小
HSSFWorkbook web=new HSSFWorkbook();//创建对象
HSSFSheet sheet=web.createSheet("导出简历Excel");//创建页
HSSFRow firstrow=sheet.createRow((short)0);//创建行
HSSFCellStyle headStyle=web.createCellStyle();//创建列
headStyle.setFillForegroundColor(HSSFColor.SKY_BLUE.index);//创建列样式
headStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
headStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
headStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
headStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
headStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
headStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
headStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
headStyle.setWrapText(true);


ResumeInfoEntity resume=ApplicationEntityUtil.getResumeInfoEntity();//实例化一个实体
//以数组的形式 创建表头样式
String[] names=new String[11];
names[0] ="编号";
names[1] ="名称";
names[2] ="籍贯";
names[3] ="性别";
names[4] ="学历";
names[5] ="专业";
names[6] ="毕业院校";
names[7] ="年龄";
names[8] ="邮箱";
names[9] ="联系方式";
names[10]="教育经历";
//循环创建一个表头
for(int i=0;i<names.length;i++){
HSSFCell firstcell=firstrow.createCell((short) i);//创建第I列
firstcell.setEncoding(HSSFCell.ENCODING_UTF_16);//编码格式为UTF-16
firstcell.setCellValue(names[i]);//往表格里面放入值

}
//循环创建行并放入值
for(int j=0;j<list.size();j++){
HSSFRow row = sheet.createRow(j+ 1);
HSSFCellStyle cellstyle=web.createCellStyle();
cellstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
//每当创建一行的时候就赋值一次 List集里面放的本来就是Resume对象
resume=list.get(j);
for(int count=0;count<names.length;count++){
HSSFCell onecell=row.createCell((short)0);
onecell.setEncoding(HSSFCell.ENCODING_UTF_16);
onecell.setCellValue(resume.getResumeId());//编号

HSSFCell twocell=row.createCell((short)1);
twocell.setEncoding(HSSFCell.ENCODING_UTF_16);
twocell.setCellValue(resume.getResumeName());//名称

HSSFCell threecell=row.createCell((short)2);
threecell.setEncoding(HSSFCell.ENCODING_UTF_16);
threecell.setCellValue(resume.getResumeBirthplace());//籍贯

HSSFCell fourcell=row.createCell((short)3);
fourcell.setEncoding(HSSFCell.ENCODING_UTF_16);
fourcell.setCellValue(resume.getResumeSex());//性别

HSSFCell fivecell=row.createCell((short)4);
fivecell.setEncoding(HSSFCell.ENCODING_UTF_16);
fivecell.setCellValue(resume.getResumeEducation());//学历

HSSFCell sixcell=row.createCell((short)5);//专业
sixcell.setEncoding(HSSFCell.ENCODING_UTF_16);
sixcell.setCellValue(resume.getResumeSpecialty());


HSSFCell sevencell=row.createCell((short)6);//毕业院校
sevencell.setEncoding(HSSFCell.ENCODING_UTF_16);
sevencell.setCellValue(resume.getGraduateSchool());

HSSFCell eighrcell=row.createCell((short)7);//年龄
eighrcell.setEncoding(HSSFCell.ENCODING_UTF_16);
eighrcell.setCellValue(resume.getResumeAge());

HSSFCell ninecell=row.createCell((short)8);//邮箱
ninecell.setEncoding(HSSFCell.ENCODING_UTF_16);
ninecell.setCellValue(resume.getResumeMailbox());

HSSFCell tencell=row.createCell((short)9);//联系方式
tencell.setEncoding(HSSFCell.ENCODING_UTF_16);
tencell.setCellValue(resume.getResumeTelephone());

}
}
// 创建文件输出流,准备输出电子表格
OutputStream out = new FileOutputStream("e:/ResumeInfoTest.xls");
web.write(out);
out.close();
System.out.println("数据库导出成功");

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值