List of usage examples for org.apache.poi.hssf.usermodel HSSFWorkbook createCellStyle
@Override
public HSSFCellStyle createCellStyle()
From source file:com.conecta.sat.utils.BuildXls.java
@Override protected void buildExcelDocument(Map<String, Object> map, org.apache.poi.hssf.usermodel.HSSFWorkbook workbook, HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception { hsr1.setContentType("application/vnd.ms-excel"); DateFormat name = new SimpleDateFormat("ddMMyyyyhhmmss"); hsr1.setHeader("Content-disposition", "attachment; filename=Reporte" + name.format(new Date()) + ".xls"); HSSFSheet sheet = workbook.createSheet("Inventario"); sheet.setDefaultColumnWidth(30);/*from ww w . j a v a 2 s . c o m*/ CellStyle style = workbook.createCellStyle(); List<PdfDTO> list = (List<PdfDTO>) map.get("list"); HSSFRow header = sheet.createRow(0); for (int i = 0; i < sColumnas.length; i++) { header.createCell(i).setCellValue(sColumnas[i]); header.getCell(i).setCellStyle(style); } int rowCount = 1; HSSFCellStyle my_style_0 = workbook.createCellStyle(); for (PdfDTO pdfDto : list) { HSSFRow aRow = sheet.createRow(rowCount++); aRow.createCell(0).setCellValue(pdfDto.getSerial()); aRow.createCell(1).setCellValue(pdfDto.getEntrega()); aRow.createCell(2).setCellValue(pdfDto.getEntrega()); aRow.createCell(3).setCellValue(pdfDto.getActivacion()); aRow.createCell(4).setCellValue(pdfDto.getCentro()); aRow.createCell(5).setCellValue(pdfDto.getTipo()); aRow.createCell(6).setCellValue(pdfDto.getCliente()); aRow.createCell(7).setCellValue(pdfDto.getFolioPivotal()); // aRow.createCell(8).setCellValue( pdfDto.getIdUnico() ); aRow.createCell(8).setCellValue(pdfDto.getLastUpdate()); } }
From source file:com.creativity.controller.PesquisaFichasBean.java
public void posProcessarXls(Object documento) { HSSFWorkbook planilha = (HSSFWorkbook) documento; HSSFSheet folha = planilha.getSheetAt(0); HSSFRow cabecalho = folha.getRow(0); HSSFCellStyle estiloCelula = planilha.createCellStyle(); HSSFFont fonteCabecalho = planilha.createFont(); fonteCabecalho.setColor(IndexedColors.BLACK.getIndex()); fonteCabecalho.setBold(true);/*from ww w .j a v a 2s .co m*/ fonteCabecalho.setFontHeightInPoints((short) 10); estiloCelula.setFont(fonteCabecalho); estiloCelula.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); estiloCelula.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); for (int i = 0; i < cabecalho.getPhysicalNumberOfCells(); i++) { cabecalho.getCell(i).setCellStyle(estiloCelula); } }
From source file:com.dayuan.action.BusFileAction.java
/**???Excel*/ @RequestMapping("/exportExcel") public ModelAndView exportExcel(HttpServletRequest request, HttpServletResponse response) { Map<String, Object> context = getRootMap(); SysUser user = SessionUtils.getUser(request); BusFileModel busFileModel = new BusFileModel(); if (SuperAdmin.YES.key != user.getSuperAdmin() && user.getExcelAuth() == 0) { //busFileModel.setlUserName(user.getNickName()); busFileModel.setlUId(user.getId().toString()); }//from www. j a va2s . c o m busFileModel.setRows(500); try { List<BusFiles> list = busFileService.queryByList(busFileModel); if (list != null && list.size() > 0) { // webbookExcel HSSFWorkbook wb = new HSSFWorkbook(); // webbooksheet,Excelsheet HSSFSheet sheet = wb.createSheet("?"); HSSFSheet sheetLoan = wb.createSheet("?"); // sheet0,??poiExcel?short HSSFRow row = sheet.createRow((int) 0); HSSFRow rowLoan = sheetLoan.createRow((int) 0); // ? HSSFCellStyle style = wb.createCellStyle(); // ? style.setAlignment(HSSFCellStyle.ALIGN_CENTER); /**sheet1 ?*/ HSSFCell cell = row.createCell((short) 0); cell.setCellValue("??"); cell.setCellStyle(style); cell = row.createCell((short) 1); cell.setCellValue("??");//busfiles.lUserName cell.setCellStyle(style); cell = row.createCell((short) 2); cell.setCellValue("??");//busLoanInfo.applicationName cell.setCellStyle(style); cell = row.createCell((short) 3); cell.setCellValue("?"); //busfiles.lStatus cell.setCellStyle(style); cell = row.createCell((short) 4); cell.setCellValue(""); //busfiles.createTime cell.setCellStyle(style); cell = row.createCell((short) 5); cell.setCellValue("??"); //busLoanInfo.channel cell.setCellStyle(style); cell = row.createCell((short) 6); cell.setCellValue("?"); //buslending.loanAmount cell.setCellStyle(style); cell = row.createCell((short) 7); cell.setCellValue("?"); //buslending.openingQuota cell.setCellStyle(style); cell = row.createCell((short) 8); cell.setCellValue(""); //busBiling.creditEndDate cell.setCellStyle(style); cell = row.createCell((short) 9); cell.setCellValue("???"); //busBiling.loanAccount cell.setCellStyle(style); cell = row.createCell((short) 10); cell.setCellValue("?"); //legal.deliveryAddress cell.setCellStyle(style); /**sheet2 ?*/ HSSFCell cellLoan = rowLoan.createCell((short) 0); cellLoan.setCellValue("??"); cellLoan.setCellStyle(style); cellLoan = rowLoan.createCell((short) 1); cellLoan.setCellValue("??");//busLoanInfo.applicationName cellLoan.setCellStyle(style); cellLoan = rowLoan.createCell((short) 2); cellLoan.setCellValue("?"); //busLoanInfo.urgentCont cellLoan.setCellStyle(style); cellLoan = rowLoan.createCell((short) 3); cellLoan.setCellValue("");//busLoanInfo.relationship cellLoan.setCellStyle(style); cellLoan = rowLoan.createCell((short) 4); cellLoan.setCellValue("?");//busLoanInfo.urgentContPhone cellLoan.setCellStyle(style); cellLoan = rowLoan.createCell((short) 5); cellLoan.setCellValue("?");//busLoanInfo.urgentContAddress cellLoan.setCellStyle(style); cellLoan = rowLoan.createCell((short) 6); cellLoan.setCellValue("??"); //biling.loanCardNumber cellLoan.setCellStyle(style); cellLoan = rowLoan.createCell((short) 7); cellLoan.setCellValue("1"); cellLoan.setCellStyle(style); cellLoan = rowLoan.createCell((short) 8); cellLoan.setCellValue("?1"); cellLoan.setCellStyle(style); cellLoan = rowLoan.createCell((short) 9); cellLoan.setCellValue("???1"); cellLoan.setCellStyle(style); cellLoan = rowLoan.createCell((short) 10); cellLoan.setCellValue("?1"); cellLoan.setCellStyle(style); cellLoan = rowLoan.createCell((short) 11); cellLoan.setCellValue("2"); cellLoan.setCellStyle(style); cellLoan = rowLoan.createCell((short) 12); cellLoan.setCellValue("?2"); cellLoan.setCellStyle(style); cellLoan = rowLoan.createCell((short) 13); cellLoan.setCellValue("???2"); cellLoan.setCellStyle(style); cellLoan = rowLoan.createCell((short) 14); cellLoan.setCellValue("?2"); cellLoan.setCellStyle(style); cellLoan = rowLoan.createCell((short) 15); cellLoan.setCellValue(""); cellLoan.setCellStyle(style); cellLoan = rowLoan.createCell((short) 16); cellLoan.setCellValue("??"); cellLoan.setCellStyle(style); cellLoan = rowLoan.createCell((short) 17); cellLoan.setCellValue("????"); cellLoan.setCellStyle(style); cellLoan = rowLoan.createCell((short) 18); cellLoan.setCellValue("??"); cellLoan.setCellStyle(style); cellLoan = rowLoan.createCell((short) 19); cellLoan.setCellValue("??"); cellLoan.setCellStyle(style); cellLoan = rowLoan.createCell((short) 20); cellLoan.setCellValue("?"); cellLoan.setCellStyle(style); for (int i = 0; i < list.size(); i++) { BusFiles busFiles = list.get(i); Integer lId = busFiles.getId(); BusLoanInfo busLoanInfo = busLoanInfoService.queryByLId(lId); BusLending busLending = busLendingService.queryByBId(lId); BusBiling busBiling = busBilingService.queryByBId(lId); BusLoanInfoLegal legal = busLoanInfoLegalService.getBusLoanInfoLegal(lId); List<BusLoanInfoShop> shopList = busLoanInfoShopService.queryListByBId(lId); /**rowsheet1*/ row = sheet.createRow((int) 1 + i); row.createCell((short) 0).setCellValue(i + 1); row.createCell((short) 1).setCellValue(busFiles.getlUserName()); row.createCell((short) 3).setCellValue(busFiles.getlStatus()); row.createCell((short) 4).setCellValue( DateUtil.getFormattedDateUtil((Date) busFiles.getCreateTime(), "yyyy-MM-dd HH:mm:ss")); /**rowLoansheet2*/ rowLoan = sheetLoan.createRow((int) 1 + i); rowLoan.createCell((short) 0).setCellValue(i + 1); if (busLoanInfo != null) { row.createCell((short) 2).setCellValue(busLoanInfo.getApplicationName()); row.createCell((short) 5).setCellValue(busLoanInfo.getChannel()); rowLoan.createCell((short) 1).setCellValue(busLoanInfo.getApplicationName()); rowLoan.createCell((short) 2).setCellValue(busLoanInfo.getUrgentCont()); rowLoan.createCell((short) 3).setCellValue(busLoanInfo.getRelationship()); rowLoan.createCell((short) 4).setCellValue(busLoanInfo.getUrgentContPhone()); rowLoan.createCell((short) 5).setCellValue(busLoanInfo.getUrgentContAddress()); } else { row.createCell((short) 2).setCellValue(""); row.createCell((short) 5).setCellValue(""); rowLoan.createCell((short) 1).setCellValue(""); rowLoan.createCell((short) 2).setCellValue(""); rowLoan.createCell((short) 3).setCellValue(""); rowLoan.createCell((short) 4).setCellValue(""); rowLoan.createCell((short) 5).setCellValue(""); } if (busLending != null) { row.createCell((short) 6).setCellValue(busLending.getLoanAmount()); row.createCell((short) 7).setCellValue(busLending.getOpeningQuota()); } else { row.createCell((short) 6).setCellValue(""); row.createCell((short) 7).setCellValue(""); } if (busBiling != null) { row.createCell((short) 8).setCellValue(busBiling.getCreditEndDate()); row.createCell((short) 9).setCellValue(busBiling.getLoanAccount()); rowLoan.createCell((short) 6).setCellValue(busBiling.getLoanCardNumber());//?? rowLoan.createCell((short) 15).setCellValue(DateUtil .getFormattedDateUtil((Date) busBiling.getCheckDate(), "yyyy-MM-dd HH:mm:ss"));// rowLoan.createCell((short) 16).setCellValue(busBiling.getCreditorIfNormal());//?? rowLoan.createCell((short) 17).setCellValue(busBiling.getGuarantorIfNormal());//???? rowLoan.createCell((short) 18).setCellValue(busBiling.getCloudLoanIfWarning());//?? rowLoan.createCell((short) 19).setCellValue(busBiling.getShopOperation());//?? rowLoan.createCell((short) 20).setCellValue(busBiling.getOtherNeedToExplained());//? } else { row.createCell((short) 8).setCellValue(""); row.createCell((short) 9).setCellValue(""); rowLoan.createCell((short) 6).setCellValue("");//?? rowLoan.createCell((short) 15).setCellValue("");// rowLoan.createCell((short) 16).setCellValue("");//?? rowLoan.createCell((short) 17).setCellValue("");//???? rowLoan.createCell((short) 18).setCellValue("");//?? rowLoan.createCell((short) 19).setCellValue("");//?? rowLoan.createCell((short) 20).setCellValue("");//? } if (legal != null) { row.createCell((short) 10).setCellValue(legal.getDeliveryAddress()); } else { row.createCell((short) 10).setCellValue(""); } if (shopList != null && shopList.size() > 0) { if (shopList.size() == 1) { BusLoanInfoShop shop = shopList.get(0); rowLoan.createCell((short) 7).setCellValue(shop.getShopName());// rowLoan.createCell((short) 8).setCellValue(shop.getPlatformName());//? rowLoan.createCell((short) 9).setCellValue(shop.getSubAccount());//??? rowLoan.createCell((short) 10).setCellValue(shop.getSbuPassword());//? rowLoan.createCell((short) 11).setCellValue("");// rowLoan.createCell((short) 12).setCellValue("");//? rowLoan.createCell((short) 13).setCellValue("");//??? rowLoan.createCell((short) 14).setCellValue("");//? } else if (shopList.size() == 2) { BusLoanInfoShop shop = shopList.get(0); rowLoan.createCell((short) 7).setCellValue(shop.getShopName());// rowLoan.createCell((short) 8).setCellValue(shop.getPlatformName());//? rowLoan.createCell((short) 9).setCellValue(shop.getSubAccount());//??? rowLoan.createCell((short) 10).setCellValue(shop.getSbuPassword());//? BusLoanInfoShop shop1 = shopList.get(1); rowLoan.createCell((short) 11).setCellValue(shop1.getShopName());// rowLoan.createCell((short) 12).setCellValue(shop1.getPlatformName());//? rowLoan.createCell((short) 13).setCellValue(shop1.getSubAccount());//??? rowLoan.createCell((short) 14).setCellValue(shop1.getSbuPassword());//? } } else { rowLoan.createCell((short) 7).setCellValue(""); rowLoan.createCell((short) 8).setCellValue(""); rowLoan.createCell((short) 9).setCellValue(""); rowLoan.createCell((short) 10).setCellValue(""); rowLoan.createCell((short) 11).setCellValue(""); rowLoan.createCell((short) 12).setCellValue(""); rowLoan.createCell((short) 13).setCellValue(""); rowLoan.createCell((short) 14).setCellValue(""); } } String savePath = request.getSession().getServletContext().getRealPath( File.separator + "WEB-INF" + File.separator + "downloads" + File.separator + "excelfiles");//??,?? File savePathFile = new File(savePath); if (!savePathFile.exists()) { savePathFile.mkdirs(); } savePath = savePath + File.separator + UUID.randomUUID();//? File fileSavePath = new File(savePath); /**??*/ if (fileSavePath.exists()) { if (fileSavePath.isDirectory()) { File[] files = fileSavePath.listFiles(); for (File file : files) { file.delete(); } fileSavePath.delete(); } else { fileSavePath.delete(); } fileSavePath.mkdirs(); } else { fileSavePath.mkdirs(); } String excel = "????" + DateUtil.getNowLongTime() + ".xls";//eccel?? BufferedOutputStream fout = new BufferedOutputStream( new FileOutputStream(savePath + File.separator + excel)); //excel wb.write(fout); //excel? fout.flush(); fout.close(); //MIME response.setContentType(request.getSession().getServletContext().getMimeType(excel)); //Content-Disposition response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(excel, "UTF-8")); BufferedInputStream in = new BufferedInputStream( new FileInputStream(savePath + File.separator + excel));//,io? OutputStream out = new BufferedOutputStream(response.getOutputStream()); byte buffer[] = new byte[1024]; int len = 0; while ((len = in.read(buffer)) > 0) { out.write(buffer, 0, len);//?response? } in.close(); out.flush(); out.close(); /***/ File file = new File(savePath + File.separator + excel); if (file != null) { if (file.exists()) { file.delete();// } file = null; } /***/ if (fileSavePath != null) { if (fileSavePath.exists()) { fileSavePath.delete(); } fileSavePath = null; } if (savePathFile != null) { savePathFile = null; } log.info("Excel?"); } } catch (Exception e) { //e.printStackTrace(); log.error("exportExcel" + e.getMessage()); context.put("message", "??"); return forword("message/message", context); } return null; }
From source file:com.dayuan.action.BusinessLoanAction.java
/** * ?excel//from w w w . ja v a 2s . c om * */ @RequestMapping("/exportAllExcel") public void exportAllExcel(HttpServletRequest request, HttpServletResponse response) throws Exception { SysUser user = SessionUtils.getUser(request); BusLoanInfoModel busLoanInfoModel = new BusLoanInfoModel(); busLoanInfoModel.setuId(user.getId().toString()); busLoanInfoModel.setuName(user.getNickName()); List<BusLoanInfo> list = busLoanInfoService.queryList(busLoanInfoModel); if (list != null && list.size() > 0) { // webbookExcel HSSFWorkbook wb = new HSSFWorkbook(); // webbooksheet,Excelsheet HSSFSheet sheet = wb.createSheet("???"); // sheet0,??poiExcel?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("??"); //applicationName cell.setCellStyle(style); cell = row.createCell((short) 2); cell.setCellValue("?");//urgentCont cell.setCellStyle(style); cell = row.createCell((short) 3); cell.setCellValue(""); // relationship cell.setCellStyle(style); cell = row.createCell((short) 4); cell.setCellValue("?"); //legalPhone cell.setCellStyle(style); cell = row.createCell((short) 5); cell.setCellValue("?"); //houseAddress cell.setCellStyle(style); cell = row.createCell((short) 6); cell.setCellValue("?"); //companyName cell.setCellStyle(style); cell = row.createCell((short) 7); cell.setCellValue("?");// ?platformName cell.setCellStyle(style); cell = row.createCell((short) 8); cell.setCellValue(""); //?shopName cell.setCellStyle(style); cell = row.createCell((short) 9); cell.setCellValue("???"); //?,subAccount cell.setCellStyle(style); cell = row.createCell((short) 10); cell.setCellValue("?"); //?,sbuPassword cell.setCellStyle(style); for (int i = 0; i < list.size(); i++) { BusLoanInfo busLoanInfo = list.get(i); Integer bid = busLoanInfo.getId(); BusLoanInfoLegal busLoanInfoLegal = this.busLoanInfoLegalService.getBusLoanInfoLegal(bid); BusLoanInfoShop busLoanInfoShop = this.busLoanInfoShopService.getBusLoanInfoShop(bid); row = sheet.createRow((int) 1 + i); row.createCell((short) 0).setCellValue(i + 1); row.createCell((short) 1).setCellValue(StringUtil.getNotNullStr(busLoanInfo.getApplicationName())); row.createCell((short) 2).setCellValue(StringUtil.getNotNullStr(busLoanInfo.getUrgentCont())); row.createCell((short) 3).setCellValue(StringUtil.getNotNullStr(busLoanInfo.getRelationship())); if (busLoanInfoLegal != null) { row.createCell((short) 4) .setCellValue(StringUtil.getNotNullStr(busLoanInfoLegal.getLegalPhone())); row.createCell((short) 5) .setCellValue(StringUtil.getNotNullStr(busLoanInfoLegal.getHouseAddress())); row.createCell((short) 6) .setCellValue(StringUtil.getNotNullStr(busLoanInfoLegal.getCompanyName())); } else { row.createCell((short) 4).setCellValue(""); row.createCell((short) 5).setCellValue(""); row.createCell((short) 6).setCellValue(""); } if (busLoanInfoShop != null) { row.createCell((short) 7) .setCellValue(StringUtil.getNotNullStr(busLoanInfoShop.getPlatformName())); row.createCell((short) 8).setCellValue(StringUtil.getNotNullStr(busLoanInfoShop.getShopName())); row.createCell((short) 9) .setCellValue(StringUtil.getNotNullStr(busLoanInfoShop.getSubAccount())); row.createCell((short) 10) .setCellValue(StringUtil.getNotNullStr(busLoanInfoShop.getSbuPassword())); } else { row.createCell((short) 7).setCellValue(""); row.createCell((short) 8).setCellValue(""); row.createCell((short) 9).setCellValue(""); row.createCell((short) 10).setCellValue(""); } } String savePath = request.getSession().getServletContext().getRealPath( File.separator + "WEB-INF" + File.separator + "downloads" + File.separator + "excelfiles");//??,?? savePath = savePath + File.separator + UUID.randomUUID();//? File fileSavePath = new File(savePath); /**??*/ if (fileSavePath.exists()) { if (fileSavePath.isDirectory()) { File[] files = fileSavePath.listFiles(); for (File file : files) { file.delete(); } fileSavePath.delete(); } else { fileSavePath.delete(); } fileSavePath.mkdirs(); } else { fileSavePath.mkdirs(); } String excel = "????" + DateUtil.getNowPlusTimeMill() + ".xls";//eccel?? BufferedOutputStream fout = new BufferedOutputStream( new FileOutputStream(savePath + File.separator + excel)); // wb.write(fout); //excel? fout.flush(); fout.close(); //MIME response.setContentType(request.getSession().getServletContext().getMimeType(excel)); //Content-Disposition response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(excel, "UTF-8")); BufferedInputStream in = new BufferedInputStream( new FileInputStream(savePath + File.separator + excel));//,io? OutputStream out = new BufferedOutputStream(response.getOutputStream()); byte buffer[] = new byte[1024]; int len = 0; while ((len = in.read(buffer)) > 0) { out.write(buffer, 0, len);//?response? } in.close(); out.flush(); out.close(); /***/ File file = new File(savePath + File.separator + excel); if (file != null) { if (file.exists()) { file.delete();// } file = null; } /***/ if (fileSavePath != null) { if (fileSavePath.exists()) { fileSavePath.delete(); } fileSavePath = null; } log.info("excel?"); } }
From source file:com.dayuan.action.BusinessLoanAction.java
/** * excel//from w w w . ja va 2 s .c om * * */ @RequestMapping("/exportExcel") public void exportExcel(Integer id, HttpServletRequest request, HttpServletResponse response) throws Exception { if (id == null || id.equals("")) { log.error("?"); return; } BusLoanInfo busLoanInfo = this.busLoanInfoService.queryById(id); if (busLoanInfo == null) { log.error("busLoanInfo?"); return; } Integer bid = busLoanInfo.getId(); if (bid == null) { log.error("busLoanInfo?"); return; } BusLoanInfoLegal busLoanInfoLegal = this.busLoanInfoLegalService.getBusLoanInfoLegal(bid); BusLoanInfoShop busLoanInfoShop = this.busLoanInfoShopService.getBusLoanInfoShop(bid); // webbookExcel HSSFWorkbook wb = new HSSFWorkbook(); // webbooksheet,Excelsheet HSSFSheet sheet = wb.createSheet("???"); // sheet0,??poiExcel?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("??"); //applicationName cell.setCellStyle(style); cell = row.createCell((short) 2); cell.setCellValue("?");//urgentCont cell.setCellStyle(style); cell = row.createCell((short) 3); cell.setCellValue(""); // relationship cell.setCellStyle(style); cell = row.createCell((short) 4); cell.setCellValue("?"); //legalPhone cell.setCellStyle(style); cell = row.createCell((short) 5); cell.setCellValue("?"); //houseAddress cell.setCellStyle(style); cell = row.createCell((short) 6); cell.setCellValue("?"); //companyName cell.setCellStyle(style); cell = row.createCell((short) 7); cell.setCellValue("?");// ?platformName cell.setCellStyle(style); cell = row.createCell((short) 8); cell.setCellValue(""); //?shopName cell.setCellStyle(style); cell = row.createCell((short) 9); cell.setCellValue("???"); //?,subAccount cell.setCellStyle(style); cell = row.createCell((short) 10); cell.setCellValue("?"); //?,sbuPassword cell.setCellStyle(style); // ? ?? try { row = sheet.createRow((int) 0 + 1); row.createCell((short) 0).setCellValue(1); row.createCell((short) 1).setCellValue(StringUtil.getNotNullStr(busLoanInfo.getApplicationName())); row.createCell((short) 2).setCellValue(StringUtil.getNotNullStr(busLoanInfo.getUrgentCont())); row.createCell((short) 3).setCellValue(StringUtil.getNotNullStr(busLoanInfo.getRelationship())); if (busLoanInfoLegal != null) { row.createCell((short) 4).setCellValue(StringUtil.getNotNullStr(busLoanInfoLegal.getLegalPhone())); row.createCell((short) 5) .setCellValue(StringUtil.getNotNullStr(busLoanInfoLegal.getHouseAddress())); row.createCell((short) 6).setCellValue(StringUtil.getNotNullStr(busLoanInfoLegal.getCompanyName())); } else { row.createCell((short) 4).setCellValue(""); row.createCell((short) 5).setCellValue(""); row.createCell((short) 6).setCellValue(""); } if (busLoanInfoShop != null) { row.createCell((short) 7).setCellValue(StringUtil.getNotNullStr(busLoanInfoShop.getPlatformName())); row.createCell((short) 8).setCellValue(StringUtil.getNotNullStr(busLoanInfoShop.getShopName())); row.createCell((short) 9).setCellValue(StringUtil.getNotNullStr(busLoanInfoShop.getSubAccount())); row.createCell((short) 10).setCellValue(StringUtil.getNotNullStr(busLoanInfoShop.getSbuPassword())); } else { row.createCell((short) 7).setCellValue(""); row.createCell((short) 8).setCellValue(""); row.createCell((short) 9).setCellValue(""); row.createCell((short) 10).setCellValue(""); } // Student stu = (Student) list.get(i); // ? // cell = row.createCell((short) 3); // cell.setCellValue(new SimpleDateFormat("yyyy-mm-dd").format(stu.getBirth())); // row.createCell((short) 10).setCellValue(busLoanInfoShop.getSbuPassword());? String savePath = request.getSession().getServletContext().getRealPath( File.separator + "WEB-INF" + File.separator + "downloads" + File.separator + "excelfiles");//??,?? savePath = savePath + File.separator + UUID.randomUUID();//? File fileSavePath = new File(savePath); /**??*/ if (fileSavePath.exists()) { if (fileSavePath.isDirectory()) { File[] files = fileSavePath.listFiles(); for (File file : files) { file.delete(); } fileSavePath.delete(); } else { fileSavePath.delete(); } fileSavePath.mkdirs(); } else { fileSavePath.mkdirs(); } String excel = "????" + DateUtil.getNowPlusTimeMill() + ".xls";//eccel?? BufferedOutputStream fout = new BufferedOutputStream( new FileOutputStream(savePath + File.separator + excel)); // wb.write(fout); //excel? fout.flush(); fout.close(); //MIME response.setContentType(request.getSession().getServletContext().getMimeType(excel)); //Content-Disposition response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(excel, "UTF-8")); //,io? BufferedInputStream in = new BufferedInputStream( new FileInputStream(savePath + File.separator + excel)); OutputStream out = new BufferedOutputStream(response.getOutputStream()); byte buffer[] = new byte[1024]; int len = 0; while ((len = in.read(buffer)) > 0) { out.write(buffer, 0, len);//?response? } in.close(); out.flush(); out.close(); /***/ File file = new File(savePath + File.separator + excel); if (file != null) { if (file.exists()) { file.delete();// } file = null; } /***/ if (fileSavePath != null) { if (fileSavePath.exists()) { fileSavePath.delete(); } fileSavePath = null; } log.info("???excel?"); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.demo.bean.bandejaBean.java
public void postProcessXLS(Object document) { System.out.println("ENRO A FORMAR ARCHIVO :" + nombreArch); HSSFWorkbook wb = (HSSFWorkbook) document; HSSFSheet sheet = wb.getSheetAt(0);/* w w w. ja va2 s . com*/ HSSFRow header = sheet.getRow(0); HSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setFillForegroundColor(HSSFColor.GOLD.index); cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); for (int i = 0; i < header.getPhysicalNumberOfCells(); i++) { HSSFCell cell = header.getCell(i); cell.setCellStyle(cellStyle); } System.out.println("termino de formar el archivo"); }
From source file:com.demo.bean.ExportarGestionesBean.java
public void postProcessXLS(Object document) { HSSFWorkbook wb = (HSSFWorkbook) document; HSSFSheet sheet = wb.getSheetAt(0);//w w w .j a va2s . co m HSSFRow header = sheet.getRow(0); HSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setFillForegroundColor(HSSFColor.GOLD.index); cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); for (int i = 0; i < header.getPhysicalNumberOfCells(); i++) { HSSFCell cell = header.getCell(i); cell.setCellStyle(cellStyle); } }
From source file:com.demo.bean.ReportePagosBean.java
public void postProcessXLS(Object document) { HSSFWorkbook wb = (HSSFWorkbook) document; HSSFSheet sheet = wb.getSheetAt(0);//from ww w . j a v a2 s . c o m HSSFRow header = sheet.getRow(0); HSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setFillForegroundColor(HSSFColor.GOLD.index); cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); for (int i = 0; i < header.getPhysicalNumberOfCells(); i++) { HSSFCell cell = header.getCell(i); cell.setCellStyle(cellStyle); } LogSistema .guardarlog(this.getClass().getName() + " Method: postProcessXLS, se exporto un reporte de pagos "); }
From source file:com.demo.bean.VisitaDatosBean.java
public void postProcessXLS(Object document) { HSSFWorkbook wb = (HSSFWorkbook) document; HSSFSheet sheet = wb.getSheetAt(0);//from ww w . j av a 2s .co m HSSFRow header = sheet.getRow(0); HSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setFillForegroundColor(HSSFColor.GOLD.index); cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); for (int i = 0; i < header.getPhysicalNumberOfCells(); i++) { HSSFCell cell = header.getCell(i); cell.setCellStyle(cellStyle); } LogSistema.guardarlog(this.getClass().getName() + " Method: postProcessXLS, se exporto un reporte de visitas domiciliarias"); }
From source file:com.demo.common.extreme.view.XlsView.java
License:Apache License
private Map initStyles(HSSFWorkbook wb, short fontHeight) { Map result = new HashMap(); HSSFCellStyle titleStyle = wb.createCellStyle(); HSSFCellStyle textStyle = wb.createCellStyle(); HSSFCellStyle boldStyle = wb.createCellStyle(); HSSFCellStyle numericStyle = wb.createCellStyle(); HSSFCellStyle numericStyleBold = wb.createCellStyle(); HSSFCellStyle moneyStyle = wb.createCellStyle(); HSSFCellStyle moneyStyleBold = wb.createCellStyle(); HSSFCellStyle percentStyle = wb.createCellStyle(); HSSFCellStyle percentStyleBold = wb.createCellStyle(); // Add to export totals HSSFCellStyle moneyStyle_Totals = wb.createCellStyle(); HSSFCellStyle naStyle_Totals = wb.createCellStyle(); HSSFCellStyle numericStyle_Totals = wb.createCellStyle(); HSSFCellStyle percentStyle_Totals = wb.createCellStyle(); HSSFCellStyle textStyle_Totals = wb.createCellStyle(); result.put("titleStyle", titleStyle); result.put("textStyle", textStyle); result.put("boldStyle", boldStyle); result.put("numericStyle", numericStyle); result.put("numericStyleBold", numericStyleBold); result.put("moneyStyle", moneyStyle); result.put("moneyStyleBold", moneyStyleBold); result.put("percentStyle", percentStyle); result.put("percentStyleBold", percentStyleBold); // Add to export totals result.put("moneyStyle_Totals", moneyStyle_Totals); result.put("naStyle_Totals", naStyle_Totals); result.put("numericStyle_Totals", numericStyle_Totals); result.put("percentStyle_Totals", percentStyle_Totals); result.put("textStyle_Totals", textStyle_Totals); HSSFDataFormat format = wb.createDataFormat(); // Global fonts HSSFFont font = wb.createFont();//from ww w . ja v a 2 s . co m font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); font.setColor(HSSFColor.BLACK.index); font.setFontName(HSSFFont.FONT_ARIAL); font.setFontHeightInPoints(fontHeight); HSSFFont fontBold = wb.createFont(); fontBold.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); fontBold.setColor(HSSFColor.BLACK.index); fontBold.setFontName(HSSFFont.FONT_ARIAL); fontBold.setFontHeightInPoints(fontHeight); // Money Style moneyStyle.setFont(font); moneyStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT); moneyStyle.setDataFormat(format.getFormat(moneyFormat)); // Money Style Bold moneyStyleBold.setFont(fontBold); moneyStyleBold.setAlignment(HSSFCellStyle.ALIGN_RIGHT); moneyStyleBold.setDataFormat(format.getFormat(moneyFormat)); // Percent Style percentStyle.setFont(font); percentStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT); percentStyle.setDataFormat(format.getFormat(percentFormat)); // Percent Style Bold percentStyleBold.setFont(fontBold); percentStyleBold.setAlignment(HSSFCellStyle.ALIGN_RIGHT); percentStyleBold.setDataFormat(format.getFormat(percentFormat)); // Standard Numeric Style numericStyle.setFont(font); numericStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT); // Standard Numeric Style Bold numericStyleBold.setFont(fontBold); numericStyleBold.setAlignment(HSSFCellStyle.ALIGN_RIGHT); // Title Style titleStyle.setFont(font); titleStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); titleStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); titleStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); titleStyle.setBottomBorderColor(HSSFColor.BLACK.index); titleStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); titleStyle.setLeftBorderColor(HSSFColor.BLACK.index); titleStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); titleStyle.setRightBorderColor(HSSFColor.BLACK.index); titleStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); titleStyle.setTopBorderColor(HSSFColor.BLACK.index); titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); titleStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // Standard Text Style textStyle.setFont(font); textStyle.setWrapText(true); // Standard Text Style boldStyle.setFont(fontBold); boldStyle.setWrapText(true); // Money Style Total moneyStyle_Totals.setFont(fontBold); moneyStyle_Totals.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); moneyStyle_Totals.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); moneyStyle_Totals.setBorderBottom(HSSFCellStyle.BORDER_THIN); moneyStyle_Totals.setBottomBorderColor(HSSFColor.BLACK.index); moneyStyle_Totals.setBorderTop(HSSFCellStyle.BORDER_THIN); moneyStyle_Totals.setTopBorderColor(HSSFColor.BLACK.index); moneyStyle_Totals.setAlignment(HSSFCellStyle.ALIGN_RIGHT); moneyStyle_Totals.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); moneyStyle_Totals.setDataFormat(format.getFormat(moneyFormat)); // n/a Style Total naStyle_Totals.setFont(fontBold); naStyle_Totals.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); naStyle_Totals.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); naStyle_Totals.setBorderBottom(HSSFCellStyle.BORDER_THIN); naStyle_Totals.setBottomBorderColor(HSSFColor.BLACK.index); naStyle_Totals.setBorderTop(HSSFCellStyle.BORDER_THIN); naStyle_Totals.setTopBorderColor(HSSFColor.BLACK.index); naStyle_Totals.setAlignment(HSSFCellStyle.ALIGN_RIGHT); naStyle_Totals.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // Numeric Style Total numericStyle_Totals.setFont(fontBold); numericStyle_Totals.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); numericStyle_Totals.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); numericStyle_Totals.setBorderBottom(HSSFCellStyle.BORDER_THIN); numericStyle_Totals.setBottomBorderColor(HSSFColor.BLACK.index); numericStyle_Totals.setBorderTop(HSSFCellStyle.BORDER_THIN); numericStyle_Totals.setTopBorderColor(HSSFColor.BLACK.index); numericStyle_Totals.setAlignment(HSSFCellStyle.ALIGN_RIGHT); numericStyle_Totals.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // Percent Style Total percentStyle_Totals.setFont(fontBold); percentStyle_Totals.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); percentStyle_Totals.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); percentStyle_Totals.setBorderBottom(HSSFCellStyle.BORDER_THIN); percentStyle_Totals.setBottomBorderColor(HSSFColor.BLACK.index); percentStyle_Totals.setBorderTop(HSSFCellStyle.BORDER_THIN); percentStyle_Totals.setTopBorderColor(HSSFColor.BLACK.index); percentStyle_Totals.setAlignment(HSSFCellStyle.ALIGN_RIGHT); percentStyle_Totals.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); percentStyle_Totals.setDataFormat(format.getFormat(percentFormat)); // Text Style Total textStyle_Totals.setFont(fontBold); textStyle_Totals.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); textStyle_Totals.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); textStyle_Totals.setBorderBottom(HSSFCellStyle.BORDER_THIN); textStyle_Totals.setBottomBorderColor(HSSFColor.BLACK.index); textStyle_Totals.setBorderTop(HSSFCellStyle.BORDER_THIN); textStyle_Totals.setTopBorderColor(HSSFColor.BLACK.index); textStyle_Totals.setAlignment(HSSFCellStyle.ALIGN_LEFT); textStyle_Totals.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); return result; }