POI 基本使用方法
来源:互联网 发布:网络直播原理 编辑:程序博客网 时间:2024/06/05 03:34
使用POI生成excel文件
public void buildExcelFile(List<Orde> list, OutputStream os) throws Exception{Workbook wb = new SXSSFWorkbook(); //创建一个文档Sheet sh = wb.createSheet();//创建一个片/* 表头 */{int cellIndex = 0 ;Row title = sh.createRow(0);//创建一行title.createCell(cellIndex++).setCellValue("供应商"); //创建单元格title.createCell(cellIndex++).setCellValue("ID");title.createCell(cellIndex++).setCellValue("预订日期");title.createCell(cellIndex++).setCellValue("酒店名");title.createCell(cellIndex++).setCellValue("入住日期");title.createCell(cellIndex++).setCellValue("退房日期");title.createCell(cellIndex++).setCellValue("客人姓名");title.createCell(cellIndex++).setCellValue("晚数");title.createCell(cellIndex++).setCellValue("房间数量");title.createCell(cellIndex++).setCellValue("间晚数");title.createCell(cellIndex++).setCellValue("员工姓名");title.createCell(cellIndex++).setCellValue("shouldPayIn");title.createCell(cellIndex++).setCellValue("payIn类型");title.createCell(cellIndex++).setCellValue("payIn");title.createCell(cellIndex++).setCellValue("payIn货币");title.createCell(cellIndex++).setCellValue("payIn银行");title.createCell(cellIndex++).setCellValue("shouldPayOut");title.createCell(cellIndex++).setCellValue("payOut类型");title.createCell(cellIndex++).setCellValue("payOut");title.createCell(cellIndex++).setCellValue("payOut货币");title.createCell(cellIndex++).setCellValue("信用卡号");title.createCell(cellIndex++).setCellValue("下单同业"); title.createCell(cellIndex++).setCellValue("利润");title.createCell(cellIndex++).setCellValue("查房");title.createCell(cellIndex++).setCellValue("查房描述");CellStyle style = wb.createCellStyle();//单元格样式style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);// 设置背景颜色模式style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); // 设置背景颜色style.setAlignment(HSSFCellStyle.ALIGN_CENTER); Font font = wb.createFont();font.setFontName("黑体");font.setFontHeightInPoints((short) 13);//设置字体大小style.setFont(font);//设置字体for (int i = 0; i < cellIndex ; i++) {title.getCell(i).setCellStyle(style);sh.setColumnWidth(i, 4000);//设置列宽}}for (int i = 0; i < list.size() ; i++) {Orde orde = list.get(i);Row row = sh.createRow(i + 1);int cellIndex = 0 ;row.createCell(cellIndex++).setCellValue(obtainCellValue("orde.getSupplier.getName",orde)); row.createCell(cellIndex++).setCellValue(obtainCellValue("orde.getPId",orde));row.createCell(cellIndex++).setCellValue(obtainCellValue("orde.getBookingDate",orde));row.createCell(cellIndex++).setCellValue(obtainCellValue("orde.getHotelName",orde));{//入住日期(如果入住日期在今天之后, 显示为红色)Cell checkIn = row.createCell(cellIndex++);checkIn.setCellValue(obtainCellValue("orde.getInDate",orde));if(orde.getInDate().compareTo(new Date()) < 0 ){CellStyle style = wb.createCellStyle();style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);style.setFillForegroundColor(HSSFColor.TAN.index);checkIn.setCellStyle(style);}}row.createCell(cellIndex++).setCellValue(obtainCellValue("orde.getOutDate",orde));row.createCell(cellIndex++).setCellValue(obtainCellValue("orde.getGustName",orde));row.createCell(cellIndex++).setCellValue(obtainCellValue("orde.getNights",orde));row.createCell(cellIndex++).setCellValue(obtainCellValue("orde.getRooms",orde));row.createCell(cellIndex++).setCellValue(obtainCellValue("orde.getNrs",orde));row.createCell(cellIndex++).setCellValue(obtainCellValue("orde.getEmp.getName",orde));row.createCell(cellIndex++).setCellValue(obtainCellValue("orde.getShouldPayIn",orde));row.createCell(cellIndex++).setCellValue(obtainCellValue("orde.getPayInType.getName",orde));row.createCell(cellIndex++).setCellValue(obtainCellValue("orde.getPayIn",orde));row.createCell(cellIndex++).setCellValue(obtainCellValue("orde.getPayInCurrency",orde));row.createCell(cellIndex++).setCellValue(obtainCellValue("orde.getBank.getName",orde));row.createCell(cellIndex++).setCellValue(obtainCellValue("orde.getShouldPayOut",orde));row.createCell(cellIndex++).setCellValue(obtainCellValue("orde.getPayType.getName",orde));row.createCell(cellIndex++).setCellValue(obtainCellValue("orde.getPayOut",orde));row.createCell(cellIndex++).setCellValue(obtainCellValue("orde.getPayOutCurrency",orde));row.createCell(cellIndex++).setCellValue(obtainCellValue("orde.getCard",orde));row.createCell(cellIndex++).setCellValue(obtainCellValue("orde.getDisinfo.getName",orde));row.createCell(cellIndex++).setCellValue(obtainCellValue("orde.getProfit",orde));row.createCell(cellIndex++).setCellValue(obtainCellValue("orde.getCheckRoom",orde));row.createCell(cellIndex++).setCellValue(obtainCellValue("orde.getCheckDes",orde));}wb.write(os); //输出到输出流}
- POI 基本使用方法
- 关于POI的使用方法
- POI的基本应用
- POI----基本操作DOME
- POI 的基本操作
- poi基本导入
- POI----基本操作DOME
- POI----基本操作DOME
- POI的基本使用
- poi--2.word基本
- poi导出excel基本步骤
- POI操作excel基本使用
- POI操作excel基本使用
- poi基本用法(v3.15)
- Log4j基本使用方法
- gdb基本使用方法
- Log4j基本使用方法
- log4j基本使用方法
- RTC系统
- strut2 数据校验总结
- 删除临时文件代码(2012.10.19)
- VC中调用动态库文件Dll
- c++如何让程序只启动一个实例
- POI 基本使用方法
- WebService学习笔记--CXF基础
- 监听器 HttpSessionBindingListener ;HttpSessionActivationListener; session的活化与钝化
- 高精度乘法
- 时隙和信道
- 超详细mysql left join,right join,inner join用法分析
- 中文乱码FAT: IO charset not found
- 百度文库中的文章如何复制
- getParameter和getAttribute区别