List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet createRow
@Override public HSSFRow createRow(int rownum)
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 w w w .j a va2 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.crucialticketing.util.ReportView.java
@Override protected void buildExcelDocument(Map model, HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception { List<Ticket> ticketList = (List<Ticket>) model.get("ticketList"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); sdf.setTimeZone(TimeZone.getTimeZone("GMT+1")); //create a wordsheet HSSFSheet sheet = workbook.createSheet("Ticket Report"); HSSFRow header = sheet.createRow(0); header.createCell(0).setCellValue("Ticket ID"); header.createCell(1).setCellValue("Ticket Type"); header.createCell(2).setCellValue("Short Description"); header.createCell(3).setCellValue("Application"); header.createCell(4).setCellValue("Severity"); header.createCell(5).setCellValue("Workflow"); header.createCell(6).setCellValue("Role"); header.createCell(7).setCellValue("Workflow Status"); header.createCell(8).setCellValue("Queue"); header.createCell(9).setCellValue("SLA Clock"); header.createCell(10).setCellValue("SLA Elapsed"); header.createCell(11).setCellValue("SLA Status"); header.createCell(12).setCellValue("Created By"); header.createCell(13).setCellValue("Created On"); header.createCell(14).setCellValue("Reported By"); header.createCell(15).setCellValue("Reported On"); header.createCell(16).setCellValue("Last Updated By"); header.createCell(17).setCellValue("Last Updated On"); int rowNum = 1; for (Ticket ticket : ticketList) { //create the row data HSSFRow row = sheet.createRow(rowNum++); row.createCell(0).setCellValue(ticket.getTicketId()); row.createCell(1).setCellValue(ticket.getApplicationControl().getTicketType().getTicketTypeName()); row.createCell(2).setCellValue(ticket.getShortDescription()); row.createCell(3).setCellValue(ticket.getApplicationControl().getApplication().getApplicationName()); row.createCell(4).setCellValue(ticket.getApplicationControl().getSeverity().getSeverityLevel() + ":" + ticket.getApplicationControl().getSeverity().getSeverityName()); row.createCell(5).setCellValue(ticket.getApplicationControl().getWorkflow().getWorkflowName()); row.createCell(6).setCellValue(ticket.getApplicationControl().getRole().getRoleName()); row.createCell(7)/*ww w . j a v a 2 s .com*/ .setCellValue(ticket.getCurrentWorkflowStep().getWorkflowStatus().getWorkflowStatusName()); row.createCell(8).setCellValue(ticket.getCurrentWorkflowStep().getQueue().getQueueName()); row.createCell(9).setCellValue(ticket.getApplicationControl().getSlaClock()); row.createCell(10).setCellValue(ticket.getChangeLog().getTimeElapsed()); if (ticket.getApplicationControl().getSlaClock() >= ticket.getChangeLog().getTimeElapsed()) { row.createCell(11).setCellValue("Not Violated"); } else { row.createCell(11).setCellValue("Violated"); } row.createCell(12).setCellValue(ticket.getChangeLog().getChangeLog().get(0).getUser().getUsername()); row.createCell(13) .setCellValue(Timestamp.convTimestamp(ticket.getChangeLog().getChangeLog().get(0).getStamp())); row.createCell(14).setCellValue(ticket.getChangeLog().getChangeLog().get(0).getUser().getUsername()); row.createCell(15) .setCellValue(Timestamp.convTimestamp(ticket.getChangeLog().getChangeLog().get(0).getStamp())); row.createCell(16).setCellValue(ticket.getChangeLog().getChangeLog() .get(ticket.getChangeLog().getChangeLog().size() - 1).getUser().getUsername()); row.createCell(17).setCellValue(Timestamp.convTimestamp(ticket.getChangeLog().getChangeLog() .get(ticket.getChangeLog().getChangeLog().size() - 1).getStamp())); } }
From source file:com.crunchify.jsp.servlet.HSSFCreate.java
/** * Processes requests for both HTTP GET and POST methods. * * @param request servlet request/*from w w w . j av a 2 s . com*/ * @param response servlet response */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { DepartamentoDAO d = new DepartamentoDAO(); response.setContentType("application/vnd.ms-excel"); HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("new sheet"); Map<String, Object[]> data = new HashMap<String, Object[]>(); data.put("1", new Object[] { "Emp No.", "Name" }); for (int i = 0; i < d.findAll().size(); i++) { data.put("2", new Object[] { d.findAll().get(i).getNom_departamento(), d.findAll().get(i).getNom_departamento() }); } Set<String> keyset = data.keySet(); int rownum = 0; for (String key : keyset) { Row row = sheet.createRow(rownum++); Object[] objArr = data.get(key); int cellnum = 0; for (Object obj : objArr) { Cell cell = row.createCell(cellnum++); if (obj instanceof Date) { cell.setCellValue((Date) obj); } else if (obj instanceof Boolean) { cell.setCellValue((Boolean) obj); } else if (obj instanceof String) { cell.setCellValue((String) obj); } else if (obj instanceof Double) { cell.setCellValue((Double) obj); } } } // Write the output OutputStream out = response.getOutputStream(); wb.write(out); out.close(); }
From source file:com.dawg6.web.dhcalc.server.ExportExcel.java
License:Open Source License
private void addSkillSummary(HSSFSheet skillSummary) { createTableHeader(skillSummary, 0, "Skill"); createTableHeader(skillSummary, 1, "# Attacks"); createTableHeader(skillSummary, 2, "Per Attack"); createTableHeader(skillSummary, 3, "Total"); createTableHeader(skillSummary, 4, "DPS"); createTableHeader(skillSummary, 5, "% of Total"); double total = 0; for (Damage d : data.output.damages) { total += d.actualDamage;//from w w w . j ava2 s. co m } int i = 1; for (Map.Entry<DamageSource, DamageHolder> e : data.skillDamages.entrySet()) { Row row = skillSummary.createRow(i++); ActiveSkill skill = e.getKey().skill; GemSkill gem = e.getKey().gem; DamageHolder d = e.getValue(); addTableCell(row, 0, (skill != null) ? skill.getLongName() : gem.getDisplayName()); addTableCell(row, 1, d.attacks); addTableCell(row, 2, Math.round((d.damage) / d.attacks)); addTableCell(row, 3, d.damage); addTableCell(row, 4, Math.round((d.damage) / data.output.duration)); addTableCell(row, 5, Math.round(10000.0 * d.damage / total) / 10000.0, pctStyle); } for (i = 0; i < 6; i++) { skillSummary.autoSizeColumn(i, true); } }
From source file:com.dawg6.web.dhcalc.server.ExportExcel.java
License:Open Source License
private void addShooterSummary(HSSFSheet shooterSummary) { createTableHeader(shooterSummary, 0, "Shooter"); createTableHeader(shooterSummary, 1, "# Attacks"); createTableHeader(shooterSummary, 2, "Per Attack"); createTableHeader(shooterSummary, 3, "Total"); createTableHeader(shooterSummary, 4, "DPS"); createTableHeader(shooterSummary, 5, "% of Total"); double total = 0; for (Damage d : data.output.damages) { total += d.actualDamage;// ww w . j av a 2s.co m } int i = 1; for (Map.Entry<String, DamageHolder> e : data.shooterDamages.entrySet()) { Row row = shooterSummary.createRow(i++); DamageHolder d = e.getValue(); addTableCell(row, 0, e.getKey()); addTableCell(row, 1, d.attacks); addTableCell(row, 2, Math.round((d.damage) / d.attacks)); addTableCell(row, 3, d.damage); addTableCell(row, 4, Math.round((d.damage) / data.output.duration)); addTableCell(row, 5, Math.round(10000.0 * d.damage / total) / 10000.0, pctStyle); } for (i = 0; i < 6; i++) { shooterSummary.autoSizeColumn(i, true); } }
From source file:com.dawg6.web.dhcalc.server.ExportExcel.java
License:Open Source License
private void addTypeSummary(HSSFSheet typeSummary) { createTableHeader(typeSummary, 0, "Type"); createTableHeader(typeSummary, 1, "# Attacks"); createTableHeader(typeSummary, 2, "Per Attack"); createTableHeader(typeSummary, 3, "Total"); createTableHeader(typeSummary, 4, "DPS"); createTableHeader(typeSummary, 5, "% of Total"); double total = 0; for (Damage d : data.output.damages) { total += d.actualDamage;// ww w . java 2 s . c o m } int i = 1; for (Map.Entry<DamageType, DamageHolder> e : data.types.entrySet()) { Row row = typeSummary.createRow(i++); DamageHolder d = e.getValue(); addTableCell(row, 0, e.getKey().name()); addTableCell(row, 1, d.attacks); addTableCell(row, 2, Math.round((d.damage) / d.attacks)); addTableCell(row, 3, d.damage); addTableCell(row, 4, Math.round((d.damage) / data.output.duration)); addTableCell(row, 5, Math.round(10000.0 * d.damage / total) / 10000.0, pctStyle); } for (i = 0; i < 6; i++) { typeSummary.autoSizeColumn(i, true); } }
From source file:com.dawg6.web.dhcalc.server.ExportExcel.java
License:Open Source License
private void addDamageLog(HSSFSheet damageLog) { int col = 0;//from ww w.ja va 2 s . c o m createTableHeader(damageLog, col++, "Time"); createTableHeader(damageLog, col++, "Shooter"); createTableHeader(damageLog, col++, "Skill"); createTableHeader(damageLog, col++, "Rune"); createTableHeader(damageLog, col++, "Type"); createTableHeader(damageLog, col++, "+/- Hatred"); createTableHeader(damageLog, col++, "Hatred"); createTableHeader(damageLog, col++, "+/- Disc"); createTableHeader(damageLog, col++, "Disc"); createTableHeader(damageLog, col++, "Damage"); createTableHeader(damageLog, col++, "Target HP"); createTableHeader(damageLog, col++, "% HP"); createTableHeader(damageLog, col++, "Target"); createTableHeader(damageLog, col++, "Notes"); createTableHeader(damageLog, col++, "Calculations"); double total = 0; for (Damage d : data.output.damages) { total += d.actualDamage; } for (int i = 0; i < data.output.damages.length; i++) { Damage d = data.output.damages[i]; Row row = damageLog.createRow(i + 1); col = 0; addTableCellD(row, col++, Math.round(d.time * 100.0) / 100.0); addTableCell(row, col++, d.shooter); if (d.source != null) { ActiveSkill skill = d.source.skill; GemSkill gem = d.source.gem; Rune rune = d.source.rune; addTableCell(row, col++, (skill != null) ? skill.getLongName() : gem.getDisplayName()); addTableCell(row, col++, (rune != null) ? rune.getLongName() : "N/A"); } else { col += 2; } if (d.type != null) { addTableCell(row, col++, d.type.name()); } else { col++; } if (d.hatred != 0) { addTableCellD(row, col++, Math.round(d.hatred * 10.0) / 10.0); } else { col++; } addTableCellD(row, col++, Math.round(d.currentHatred * 10.0) / 10.0); if (d.disc != 0) { addTableCellD(row, col++, Math.round(d.disc * 10.0) / 10.0); } else { col++; } addTableCellD(row, col++, Math.round(d.currentDisc * 10.0) / 10.0); if (d.damage > 0) { addTableCell(row, col++, Math.round(d.damage)); addTableCell(row, col++, (double) Math.round(d.targetHp)); addTableCell(row, col++, Math.round(d.targetHpPercent * 1000.0) / 10.0 + "%"); } else { col += 3; } if (d.target != null) { addTableCell(row, col++, d.target.toString()); } else { col += 2; } if (d.note != null) { addTableCell(row, col++, d.note); } else { col++; } if (d.log != null) { addTableCell(row, col++, d.log); } else { col++; } } for (int i = 0; i < 12; i++) { damageLog.autoSizeColumn(i, true); } }
From source file:com.dawg6.web.dhcalc.server.ExportExcel.java
License:Open Source License
private Cell createTableHeader(HSSFSheet sheet, int col, String label) { int n = sheet.getPhysicalNumberOfRows(); Row row = null;/* w w w .ja v a 2 s .c o m*/ if (n < 1) row = sheet.createRow(0); else row = sheet.getRow(0); Cell cell = row.createCell(col); cell.setCellValue(label); cell.setCellStyle(boldStyle); CellUtil.setAlignment(cell, sheet.getWorkbook(), CellStyle.ALIGN_CENTER); return cell; }
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()); }//w ww . j a va 2s . co 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 ww w . j a va2 s . 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?"); } }