List of usage examples for org.apache.poi.hssf.usermodel HSSFWorkbook write
private void write(POIFSFileSystem fs) throws IOException
From source file:com.jeecg.controller.giftbook.ApiTruckController.java
/** * excel ?/*from ww w . j a v a 2s . c o m*/ * * @param request * @param response */ @RequestMapping(params = "exportXlsByT") public void exportXlsByT(TruckEntity truck, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { response.setContentType("application/vnd.ms-excel"); String codedFileName = null; OutputStream fOut = null; try { codedFileName = "truck"; // ?????? if (BrowserUtils.isIE(request)) { response.setHeader("content-disposition", "attachment;filename=" + java.net.URLEncoder.encode(codedFileName, "UTF-8") + ".xls"); } else { String newtitle = new String(codedFileName.getBytes("UTF-8"), "ISO8859-1"); response.setHeader("content-disposition", "attachment;filename=" + newtitle + ".xls"); } // HSSFWorkbook workbook = null; workbook = ExcelExportUtil .exportExcel( new ExcelTitle("truck", ":" + ResourceUtil.getSessionUserName().getRealName(), "?"), TruckEntity.class, null); fOut = response.getOutputStream(); workbook.write(fOut); } catch (Exception e) { } finally { try { fOut.flush(); fOut.close(); } catch (IOException e) { } } }
From source file:com.jeecg.controller.giftbook.ApiTruckRouteController.java
/** * excel/* ww w . ja v a2 s .com*/ * * @param request * @param response */ @RequestMapping(params = "exportXls") public void exportXls(TruckRouteEntity truckRoute, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { response.setContentType("application/vnd.ms-excel"); String codedFileName = null; OutputStream fOut = null; try { codedFileName = "truck_route"; // ?????? if (BrowserUtils.isIE(request)) { response.setHeader("content-disposition", "attachment;filename=" + java.net.URLEncoder.encode(codedFileName, "UTF-8") + ".xls"); } else { String newtitle = new String(codedFileName.getBytes("UTF-8"), "ISO8859-1"); response.setHeader("content-disposition", "attachment;filename=" + newtitle + ".xls"); } // HSSFWorkbook workbook = null; CriteriaQuery cq = new CriteriaQuery(TruckRouteEntity.class, dataGrid); org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, truckRoute, request.getParameterMap()); List<TruckRouteEntity> truckRoutes = this.truckRouteService.getListByCriteriaQuery(cq, false); workbook = ExcelExportUtil.exportExcel( new ExcelTitle("truck_route", ":" + ResourceUtil.getSessionUserName().getRealName(), "?"), TruckRouteEntity.class, truckRoutes); fOut = response.getOutputStream(); workbook.write(fOut); } catch (Exception e) { } finally { try { fOut.flush(); fOut.close(); } catch (IOException e) { } } }
From source file:com.jeecg.controller.giftbook.ApiTruckRouteController.java
/** * excel ?// w ww .j a v a 2 s .c o m * * @param request * @param response */ @RequestMapping(params = "exportXlsByT") public void exportXlsByT(TruckRouteEntity truckRoute, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { response.setContentType("application/vnd.ms-excel"); String codedFileName = null; OutputStream fOut = null; try { codedFileName = "truck_route"; // ?????? if (BrowserUtils.isIE(request)) { response.setHeader("content-disposition", "attachment;filename=" + java.net.URLEncoder.encode(codedFileName, "UTF-8") + ".xls"); } else { String newtitle = new String(codedFileName.getBytes("UTF-8"), "ISO8859-1"); response.setHeader("content-disposition", "attachment;filename=" + newtitle + ".xls"); } // HSSFWorkbook workbook = null; workbook = ExcelExportUtil.exportExcel( new ExcelTitle("truck_route", ":" + ResourceUtil.getSessionUserName().getRealName(), "?"), TruckRouteEntity.class, null); fOut = response.getOutputStream(); workbook.write(fOut); } catch (Exception e) { } finally { try { fOut.flush(); fOut.close(); } catch (IOException e) { } } }
From source file:com.jitendrasinghnz.excelreadutility.ExcelReadStringArrayXSL.java
License:Open Source License
public void setOutputSingletResult(String[][] inputData, String[] outputResult, String filePath) { String[][] outputResultTwoDimensionArray; outputResultTwoDimensionArray = new String[inputData.length][inputData[0].length + 1]; Path folderPath = null;//from ww w. j a v a 2s.com try { folderPath = Paths.get(filePath); } catch (InvalidPathException i) { System.out.println("Please Check whether " + filePath + " exist "); } for (int i = 0; i < outputResultTwoDimensionArray.length; i++) { for (int j = 0; j < outputResultTwoDimensionArray[i].length; j++) { if (j == (outputResultTwoDimensionArray[i].length - 1)) { for (int k = j; k < outputResultTwoDimensionArray[i].length; k++) { outputResultTwoDimensionArray[i][k] = outputResult[i]; } } else outputResultTwoDimensionArray[i][j] = inputData[i][j]; } } CharSequence filepathWindows = "\\"; CharSequence filepathGNULinux = "/"; try { if (filePath.contains(filepathWindows) || filePath.contains(filepathGNULinux)) { String filename = "test_output_singlet_" + String.valueOf(System.currentTimeMillis()) + ".xls"; String finalFileName = filePath + filename; FileOutputStream outputFile = new FileOutputStream(finalFileName); HSSFWorkbook hSSFWorkbook = new HSSFWorkbook(); HSSFSheet hSSFSheet = hSSFWorkbook.createSheet("output"); for (int i = 0; i < outputResultTwoDimensionArray.length; i++) { HSSFRow row = hSSFSheet.createRow(i); for (int j = 0; j < outputResultTwoDimensionArray[i].length; j++) { HSSFCell cell = row.createCell(j); cell.setCellValue(outputResultTwoDimensionArray[i][j]); } } hSSFWorkbook.write(outputFile); outputFile.flush(); outputFile.close(); System.out.println("An output file named \"" + filename + "\" was created at \"" + filePath + "\""); System.out.println("Good Bye !!!"); } } catch (FileNotFoundException fnfe) { System.out.println("Sorry " + filePath + " does not exist"); } catch (IOException ioe) { System.out.println("Error to open/close file from path " + filePath); } }
From source file:com.jitendrasinghnz.excelreadutility.ExcelReadStringArrayXSL.java
License:Open Source License
public void setOutputResult(String[][] inputData, String[][] outputResult, String filePath) { String[][] outputResultTwoDimensionArray; outputResultTwoDimensionArray = new String[inputData.length][inputData[0].length + outputResult[0].length]; Path folderPath = null;//from w w w .j av a 2s . co m try { folderPath = Paths.get(filePath); } catch (InvalidPathException i) { System.out.println("Please Check whether " + filePath + " exist "); } for (int i = 0; i < outputResultTwoDimensionArray.length; i++) { for (int j = 0; j < outputResultTwoDimensionArray[i].length; j++) { if (j >= (outputResultTwoDimensionArray[i].length - outputResult[i].length)) { outputResultTwoDimensionArray[i][j] = outputResult[i][j - (outputResultTwoDimensionArray[i].length - outputResult[i].length)]; } else outputResultTwoDimensionArray[i][j] = inputData[i][j]; } } CharSequence filepathWindows = "\\"; CharSequence filepathGNULinux = "/"; try { if (filePath.contains(filepathWindows) || filePath.contains(filepathGNULinux)) { String filename = "test_output_" + String.valueOf(System.currentTimeMillis()) + ".xls"; String finalFileName = filePath + filename; FileOutputStream outputFile = new FileOutputStream(finalFileName); HSSFWorkbook hSSFWorkbook = new HSSFWorkbook(); HSSFSheet hSSFSheet = hSSFWorkbook.createSheet("output"); for (int i = 0; i < outputResultTwoDimensionArray.length; i++) { HSSFRow row = hSSFSheet.createRow(i); for (int j = 0; j < outputResultTwoDimensionArray[i].length; j++) { HSSFCell cell = row.createCell(j); cell.setCellValue(outputResultTwoDimensionArray[i][j]); } } hSSFWorkbook.write(outputFile); outputFile.flush(); outputFile.close(); System.out.println("An output file named \"" + filename + "\" was created at \"" + filePath + "\""); System.out.println("Good Bye !!!"); } } catch (FileNotFoundException fnfe) { System.out.println("Sorry " + filePath + " does not exist"); } catch (IOException ioe) { System.out.println("Error to open/close file from path " + filePath); } }
From source file:com.jshuabo.reportcenter.server.service.automoblie.impl.DefaultAutoRecordServiceImpl.java
License:Open Source License
@Override public String importDataToExcel(HttpServletRequest request, HttpServletResponse response) { String realPath = request.getSession().getServletContext().getRealPath("/"); Map<String, Object> params = new HashMap<String, Object>(); Subject subject = SecurityUtils.getSubject(); User user = (User) subject.getPrincipal(); String userId = user.getId().toString(); if (!"1".equals(userId) && !"50".equals(userId) && !"38".equals(userId) && !"53".equals(userId) && !"15".equals(userId) && !"16".equals(userId) && !"17".equals(userId)) { // FY FY_NJ 33 params.put("subStation", user.getId()); } else {/*from w w w . j a va2 s . c o m*/ // ggz bj WHY zht params.put("subStation", request.getParameter("subStation")); } params.put("name", request.getParameter("name")); params.put("sortOrder", null); params.put("offset", null); params.put("rows", null); List<AutoRecordData> autoRecordDataList = autoRecordDataMapper.page(params); String _fileName = null; FileOutputStream out = null; Map<String, Object> subStationMap = new HashMap<String, Object>(); subStationMap.put("18", "?"); subStationMap.put("19", ""); subStationMap.put("20", ""); subStationMap.put("21", ""); subStationMap.put("22", "?"); subStationMap.put("23", ""); subStationMap.put("24", "?"); subStationMap.put("25", ""); subStationMap.put("26", ""); subStationMap.put("27", "?"); subStationMap.put("28", ""); subStationMap.put("29", ""); subStationMap.put("30", ""); subStationMap.put("31", "?"); subStationMap.put("32", ""); subStationMap.put("33", "?"); subStationMap.put("51", ""); try { // HSSFWorkbook wb = new HSSFWorkbook(); // HSSFSheet sheet = wb.createSheet(""); HSSFRow firstRow = sheet.createRow(0); firstRow.createCell(0).setCellValue(""); firstRow.createCell(1).setCellValue("???"); firstRow.createCell(2).setCellValue(""); firstRow.createCell(3).setCellValue("?"); firstRow.createCell(4).setCellValue("?(???)"); firstRow.createCell(5).setCellValue("?"); firstRow.createCell(6).setCellValue(""); firstRow.createCell(7).setCellValue(""); firstRow.createCell(8).setCellValue("??"); firstRow.createCell(9).setCellValue("???"); firstRow.createCell(10).setCellValue("???"); firstRow.createCell(11).setCellValue("??"); firstRow.createCell(12).setCellValue("??"); firstRow.createCell(13).setCellValue(""); firstRow.createCell(14).setCellValue("??"); firstRow.createCell(15).setCellValue(""); firstRow.createCell(16).setCellValue("?"); firstRow.createCell(17).setCellValue("???"); firstRow.createCell(18).setCellValue("???"); firstRow.createCell(19).setCellValue("???"); firstRow.createCell(20).setCellValue("?"); firstRow.createCell(21).setCellValue("??"); firstRow.createCell(22).setCellValue("????"); firstRow.createCell(23).setCellValue("????"); firstRow.createCell(24).setCellValue("???"); firstRow.createCell(25).setCellValue("??"); firstRow.createCell(26).setCellValue("??"); firstRow.createCell(27).setCellValue("???"); firstRow.createCell(28).setCellValue("??"); firstRow.createCell(29).setCellValue("??"); firstRow.createCell(30).setCellValue("??"); firstRow.createCell(31).setCellValue("??"); firstRow.createCell(32).setCellValue("??"); firstRow.createCell(33).setCellValue("????"); firstRow.createCell(34).setCellValue("?"); if (autoRecordDataList.size() > 0) { for (int j = 1; j < autoRecordDataList.size() + 1; ++j) { HSSFRow row = sheet.createRow(j); // subStation HSSFCell subStation = row.createCell(0); subStation.setCellValue( subStationMap.get(autoRecordDataList.get(j - 1).getSubStation()).toString()); // deputyCard ??? HSSFCell deputyCard = row.createCell(1); deputyCard.setCellValue(autoRecordDataList.get(j - 1).getDeputyCard()); // carKind HSSFCell carKind = row.createCell(2); carKind.setCellValue(autoRecordDataList.get(j - 1).getCarKind()); // licenseNo ? HSSFCell licenseNo = row.createCell(3); licenseNo.setCellValue(autoRecordDataList.get(j - 1).getLicenseNo()); // license ?(???) HSSFCell license = row.createCell(4); license.setCellValue(autoRecordDataList.get(j - 1).getLicense()); // licenseDate ? HSSFCell licenseDate = row.createCell(5); licenseDate.setCellValue(null == autoRecordDataList.get(j - 1).getLicenseDate() ? "" : DateFormatUtils.format(autoRecordDataList.get(j - 1).getLicenseDate(), DateFormatUtils.ymd)); // licenseName HSSFCell licenseName = row.createCell(6); licenseName.setCellValue(autoRecordDataList.get(j - 1).getLicenseName()); // inspectionDate HSSFCell inspectionDate = row.createCell(7); inspectionDate.setCellValue(null == autoRecordDataList.get(j - 1).getInspectionDate() ? "" : DateFormatUtils.format(autoRecordDataList.get(j - 1).getInspectionDate(), DateFormatUtils.ymd)); // name ?? HSSFCell name = row.createCell(8); name.setCellValue(autoRecordDataList.get(j - 1).getName()); // idCard ??? HSSFCell idCard = row.createCell(9); idCard.setCellValue(autoRecordDataList.get(j - 1).getIdCard()); // ftReceive ??? HSSFCell ftReceive = row.createCell(10); ftReceive.setCellValue(null == autoRecordDataList.get(j - 1).getFtReceive() ? "" : DateFormatUtils.format(autoRecordDataList.get(j - 1).getFtReceive(), DateFormatUtils.ymd)); // changeDate ?? HSSFCell changeDate = row.createCell(11); changeDate.setCellValue(null == autoRecordDataList.get(j - 1).getChangeDate() ? "" : DateFormatUtils.format(autoRecordDataList.get(j - 1).getChangeDate(), DateFormatUtils.ymd)); // telephone ?? HSSFCell telephone = row.createCell(12); telephone.setCellValue(autoRecordDataList.get(j - 1).getTelephone()); // strongInsDate HSSFCell strongInsDate = row.createCell(13); strongInsDate.setCellValue(null == autoRecordDataList.get(j - 1).getStrongInsDate() ? "" : DateFormatUtils.format(autoRecordDataList.get(j - 1).getStrongInsDate(), DateFormatUtils.ymd)); // tLInsurance ?? (?) HSSFCell tLInsurance = row.createCell(14); Double _tLInsurance = autoRecordDataList.get(j - 1).gettLInsurance(); if (null == _tLInsurance) { tLInsurance.setCellValue(""); } else { tLInsurance.setCellValue(_tLInsurance); } // tLInsuranceDate HSSFCell tLInsuranceDate = row.createCell(15); tLInsuranceDate.setCellValue(null == autoRecordDataList.get(j - 1).gettLInsuranceDate() ? "" : DateFormatUtils.format(autoRecordDataList.get(j - 1).gettLInsuranceDate(), DateFormatUtils.ymd)); // policeProve ? HSSFCell policeProve = row.createCell(16); policeProve.setCellValue(autoRecordDataList.get(j - 1).getPoliceProve()); // householdCopy ??? HSSFCell householdCopy = row.createCell(17); householdCopy.setCellValue(autoRecordDataList.get(j - 1).getHouseholdCopy()); // idCardCopy ??? HSSFCell idCardCopy = row.createCell(18); idCardCopy.setCellValue(autoRecordDataList.get(j - 1).getIdCardCopy()); // licenseCopy ??? HSSFCell licenseCopy = row.createCell(19); licenseCopy.setCellValue(autoRecordDataList.get(j - 1).getLicenseCopy()); // guaranRespon ? HSSFCell guaranRespon = row.createCell(20); guaranRespon.setCellValue(autoRecordDataList.get(j - 1).getGuaranRespon()); // guaranIncome ?? HSSFCell guaranIncome = row.createCell(21); guaranIncome.setCellValue(autoRecordDataList.get(j - 1).getGuaranIncome()); // guaranHouseCopy ???? HSSFCell guaranHouseCopy = row.createCell(22); guaranHouseCopy.setCellValue(autoRecordDataList.get(j - 1).getGuaranHouseCopy()); // guaranIDCopy ???? HSSFCell guaranIDCopy = row.createCell(23); guaranIDCopy.setCellValue(autoRecordDataList.get(j - 1).getGuaranIDCopy()); // driLicenseCopy ??? HSSFCell driLicenseCopy = row.createCell(24); driLicenseCopy.setCellValue(autoRecordDataList.get(j - 1).getDriLicenseCopy()); // strongInsCopy ?? HSSFCell strongInsCopy = row.createCell(25); strongInsCopy.setCellValue(autoRecordDataList.get(j - 1).getStrongInsCopy()); // commerInsuCopy ?? HSSFCell commerInsuCopy = row.createCell(26); commerInsuCopy.setCellValue(autoRecordDataList.get(j - 1).getCommerInsuCopy()); // certificate ??? HSSFCell certificate = row.createCell(27); certificate.setCellValue(autoRecordDataList.get(j - 1).getCertificate()); // agreeDate ?? HSSFCell agreeDate = row.createCell(28); agreeDate.setCellValue(null == autoRecordDataList.get(j - 1).getAgreeDate() ? "" : DateFormatUtils.format(autoRecordDataList.get(j - 1).getAgreeDate(), DateFormatUtils.ymd)); // rentalAgreement ?? HSSFCell rentalAgreement = row.createCell(29); rentalAgreement.setCellValue(autoRecordDataList.get(j - 1).getRentalAgreement()); // strongInsPrompt ?? HSSFCell strongInsPrompt = row.createCell(30); strongInsPrompt.setCellValue(autoRecordDataList.get(j - 1).getStrongInsPrompt()); // tLInsurancePrompt ?? HSSFCell tLInsurancePrompt = row.createCell(31); tLInsurancePrompt.setCellValue(autoRecordDataList.get(j - 1).gettLInsurancePrompt()); // inspectionPrompt ?? HSSFCell inspectionPrompt = row.createCell(32); inspectionPrompt.setCellValue(autoRecordDataList.get(j - 1).getInspectionPrompt()); // changePrompt ???? HSSFCell changePrompt = row.createCell(33); changePrompt.setCellValue(autoRecordDataList.get(j - 1).getChangePrompt()); // status ? HSSFCell status = row.createCell(34); status.setCellValue(autoRecordDataList.get(j - 1).getStatus()); } } _fileName = "excel" + DateFormatUtils.format(new Date(), "yyyy-MM-dd-HH_mm_ss-SSS") + ".xls"; String fileName = realPath + File.separator + _fileName; out = new FileOutputStream(fileName); wb.write(out); } catch (Exception e) { e.printStackTrace(); } finally { // ? try { if (null != out) { out.close(); } } catch (IOException e) { e.printStackTrace(); } } return _fileName; }
From source file:com.jubination.service.CallMaintainService.java
public boolean createCallExcel(List<Call> list) { System.out.println("*******com.jubination.service.CallMaintainService.createCallExcel()"); FileOutputStream out = null;//from w w w .j av a 2s.c om HSSFWorkbook workbook = null; String excelOutputFilePath = excelOutputDirectory + "data.xls"; String excelOutputBuildFilePath = excelOutputBuildDirectory + "data.xls"; boolean flag = false; try { workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("Sample sheet"); Call[] messageArray = new Call[list.size()]; list.toArray(messageArray); Map<String, Object[]> data = new LinkedHashMap<>(); Integer index = 1; data.put(index.toString(), new Object[] { "CallFrom", "CallTo", "Status", "TrackStatus", "CallType", "DailWhomNumber", "DailCallDuration", "Message", "DateCreated", "AnsweredBy", "StartTime", "EndTime", "DateUpdated", "Duration", "Price", "Direction", "Digits", "Sid", "Uri", "RecordingUrl", "PhoneNumberSid", "AccountSid", "ForwardedFrom", "CallerName", "ParentCallSid" }); index++; for (Call message : messageArray) { data.put(index.toString(), new Object[] { message.getCallFrom(), message.getCallTo(), message.getStatus(), message.getTrackStatus(), message.getCallType(), message.getDialWhomNumber(), message.getDialCallDuration(), message.getMessage(), message.getDateCreated(), message.getAnsweredBy(), message.getStartTime(), message.getEndTime(), message.getDateUpdated(), message.getDuration(), message.getPrice(), message.getDirection(), message.getDigits(), message.getSid(), message.getUri(), message.getRecordingUrl(), message.getPhoneNumberSid(), message.getAccountSid(), message.getForwardedFrom(), message.getCallerName(), message.getParentCallSid() }); index++; } 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); } } out = new FileOutputStream(new File(excelOutputFilePath)); workbook.write(out); out = new FileOutputStream(new File(excelOutputBuildFilePath)); workbook.write(out); flag = true; System.out.println("Excel written successfully.."); } catch (Exception e) { e.printStackTrace(); } finally { try { if (workbook != null) { workbook.close(); } } catch (Exception e) { } try { if (out != null) { out.close(); } } catch (Exception e) { } } return flag; }
From source file:com.jubination.service.CallMaintainService.java
public boolean createClientExcel(String date) { System.out.println("*******com.jubination.service.CallMaintainService.createClientExcel()"); FileOutputStream out = null;/*w ww .java2 s . c o m*/ HSSFWorkbook workbook = null; String excelOutputFilePath = excelOutputDirectory + "client.xls"; String excelOutputBuildFilePath = excelOutputBuildDirectory + "client.xls"; boolean flag = false; try { workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("Client Sheet"); Map<String, Object[]> data = doReportingOperation(getClientDumpForDisplay(date)); 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); } } out = new FileOutputStream(new File(excelOutputFilePath)); workbook.write(out); out = new FileOutputStream(new File(excelOutputBuildFilePath)); workbook.write(out); flag = true; System.out.println("Excel written successfully.."); } catch (Exception e) { e.printStackTrace(); } finally { try { if (workbook != null) { workbook.close(); } } catch (Exception e) { e.printStackTrace(); } try { if (out != null) { out.close(); } } catch (Exception e) { e.printStackTrace(); } } return flag; }
From source file:com.jubination.service.CallMaintainService.java
public boolean createClientExcelAllLead(String date) { System.out.println("*******com.jubination.service.CallMaintainService.createClientExcelAllLead()"); FileOutputStream out = null;//from w w w . jav a 2 s .c o m HSSFWorkbook workbook = null; String excelOutputFilePath = excelOutputDirectory + "client.xls"; String excelOutputBuildFilePath = excelOutputBuildDirectory + "client.xls"; boolean flag = false; try { workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("Client Sheet"); List<Lead> list = getLeadDumpForDisplay(date); Lead[] messageArray = new Lead[list.size()]; list.toArray(messageArray); Map<String, Object[]> data = new LinkedHashMap<>(); Integer index = 1; data.put(index.toString(), new Object[] { "Lead id", "Name", "Number", "Email", "Campaign Name", "Pub Id", "Source", "Date", "City", "Affiliate Status", "Picked up by", "Follow ups left", "Client comment", "Lead comment", "Follow up date", "Status", "Date", "Status-1", "Date-1", " Status-2", "Date-2", " Status-3", "Date-3", " Status-4", "Date-4", " Status-5", "Date-5", " Status-6", "Date-6", " Status-7", "Date-7", " Status-8", "Date-8", " Status-9", "Date-9", " Status-10", "Date-10", " Status-11", "Date-11", " Status-12", "Date-12", " Status-13", "Date-13", " Status-14", "Date-14", " Status-15", "Date-15", "", "Final Status Beta" }); index++; for (Lead lead : messageArray) { String[] leadDetailsArray = new String[] { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" }; String[] dateDetailsArray = new String[] { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" }; String affiliateDetails = "WIP"; for (int i = 0; i < 20; i++) { dateDetailsArray[i] = ""; leadDetailsArray[i] = ""; } int count = 0; String caller = ""; if (lead != null) { if (lead.getCall().size() > 0) { for (int i = lead.getCall().size() - 1; i >= 0; i--) { if (count < 15) { Call call = lead.getCall().get(i); if (call == null) { break; } System.out.println(count + " " + i + " " + call.getDateCreated()); ////////change to allow all lead sent to thyrocare leads/////////// //////////////////////// if (call.getStatus() != null && call.getStatus().contains("busy")) { leadDetailsArray[count] = "Busy"; dateDetailsArray[count] = call.getDateCreated() + " " + call.getDuration(); if (lead.getCall().size() >= operator.getCount() - 1 && i == lead.getCall().size() - 1) { affiliateDetails = "Disconnecting the call"; } } else if (call.getStatus() != null && call.getStatus().contains("failed")) { leadDetailsArray[count] = "Failed"; dateDetailsArray[count] = call.getDateCreated() + " " + call.getDuration(); if (lead.getCall().size() >= operator.getCount() - 1 && i == lead.getCall().size() - 1) { affiliateDetails = "Not Reachable"; } } else if (call.getStatus() != null && call.getStatus().contains("no-answer")) { leadDetailsArray[count] = "No Answer"; dateDetailsArray[count] = call.getDateCreated() + " " + call.getDuration(); if (lead.getCall().size() >= operator.getCount() - 1 && i == lead.getCall().size() - 1) { affiliateDetails = "Ringing"; } } else if (call.getStatus() != null && call.getStatus().contains("completed") && call.getCallType().contains("trans")) { leadDetailsArray[count] = "Hanged up while greetings"; dateDetailsArray[count] = call.getDateCreated() + " " + call.getDuration(); if (lead.getCall().size() >= operator.getCount() - 1 && i == lead.getCall().size() - 1) { affiliateDetails = "Disconnecting the call"; } } else if (call.getTrackStatus() != null && call.getTrackStatus().contains("did not speak") && call.getCallType().contains("client-hangup")) { leadDetailsArray[count] = "Hanged up while connecting"; dateDetailsArray[count] = call.getDateCreated() + " " + call.getDuration(); if (lead.getCall().size() >= operator.getCount() - 1 && i == lead.getCall().size() - 1) { affiliateDetails = "Disconnecting the call"; } } else if (call.getTrackStatus() != null && call.getTrackStatus().contains("did not speak") && call.getCallType().contains("incomplete")) { leadDetailsArray[count] = "We missed client's call"; dateDetailsArray[count] = call.getDateCreated() + " " + call.getDuration(); if (lead.getCall().size() >= operator.getCount() - 1 && i == lead.getCall().size() - 1) { affiliateDetails = "WIP"; } caller = call.getDialWhomNumber(); } else if (call.getTrackStatus() != null && call.getTrackStatus().contains("spoke")) { if (lead.getLeadStatus() != null && (lead.getLeadStatus().contains("Follow up/Call back") || lead.getLeadStatus().contains("Lead sent to Thyrocare") || lead.getLeadStatus().contains("Not interested") || lead.getLeadStatus().contains("Not registered") || lead.getLeadStatus().contains("Language not recognizable") || lead.getLeadStatus().contains("No Service") || lead.getLeadStatus().contains("Customer complained") || lead.getLeadStatus().contains("Disapproved") || lead.getLeadStatus().contains("Rescheduled"))) { leadDetailsArray[count] = lead.getLeadStatus(); if (lead.getLeadStatus().contains("Lead sent to Thyrocare") || lead.getLeadStatus().contains("Rescheduled")) { affiliateDetails = "Interested"; } else { affiliateDetails = lead.getLeadStatus(); } dateDetailsArray[count] = call.getDateCreated() + " " + call.getDuration(); } else { if (i == lead.getCall().size() - 1) { leadDetailsArray[count] = "Spoke but not updated"; dateDetailsArray[count] = call.getDateCreated() + " " + call.getDuration(); affiliateDetails = "Spoke but not updated"; } else { leadDetailsArray[count] = lead.getLeadStatus() + ":"; dateDetailsArray[count] = call.getDateCreated() + " " + call.getDuration(); } } caller = call.getDialWhomNumber(); } else { if (i == lead.getCall().size() - 1) { if (lead.getLeadStatus() != null) { caller = call.getDialWhomNumber(); if (lead.getLeadStatus() != null && (lead.getLeadStatus().contains("Follow up/Call back") || lead.getLeadStatus().contains("Not interested") || lead.getLeadStatus().contains("Not registered") || lead.getLeadStatus() .contains("Language not recognizable") || lead.getLeadStatus().contains("No Service") || lead.getLeadStatus().contains("Customer complained") || lead.getLeadStatus().contains("Disapproved"))) { affiliateDetails = lead.getLeadStatus(); } else if (lead.getLeadStatus().contains("Lead sent to Thyrocare") || lead.getLeadStatus().contains("Rescheduled")) { affiliateDetails = "Interested"; } else if (lead.getLeadStatus().contains("Busy")) { affiliateDetails = "Disconnecting the call"; } else if (lead.getLeadStatus().contains("Failed")) { affiliateDetails = "Not Reachable"; } else if (lead.getLeadStatus().contains("No Answer")) { affiliateDetails = "Ringing"; } else if (lead.getLeadStatus().contains("Hanged up while greetings")) { affiliateDetails = "Disconnecting the call"; } else if (lead.getLeadStatus() .contains("Hanged up while connecting")) { affiliateDetails = "Disconnecting the call"; } else if (lead.getLeadStatus().contains("Spoke but not updated")) { affiliateDetails = "Spoke but not updated"; } else { affiliateDetails = lead.getLeadStatus(); } leadDetailsArray[count] = lead.getLeadStatus(); dateDetailsArray[count] = call.getDateCreated() + " " + call.getDuration(); } else { leadDetailsArray[count] = call.getStatus() + "%"; dateDetailsArray[count] = call.getDateCreated() + " " + call.getDuration(); caller = call.getDialWhomNumber(); affiliateDetails = lead.getLeadStatus(); } } else { leadDetailsArray[count] = lead.getLeadStatus() + "$"; dateDetailsArray[count] = call.getDateCreated() + " " + call.getDuration(); } } if (lead.getLeadStatus() != null && (lead.getLeadStatus().contains("Lead sent to Thyrocare") || lead.getLeadStatus().contains("Rescheduled"))) { affiliateDetails = "Interested"; } if (lead.getFollowUpDate() != null && !affiliateDetails.contains("") && !lead.getLeadStatus().contains("Follow up/Call back") && !lead.getLeadStatus().contains("Not interested") && !lead.getLeadStatus().contains("Not registered") && !lead.getLeadStatus().contains("Language not recognizable") && !lead.getLeadStatus().contains("No Service") && !lead.getLeadStatus().contains("Customer complained") && !lead.getLeadStatus().contains("Disapproved")) { affiliateDetails = "Follow up/Call back"; } if (lead.isMissedAppointment() != null && lead.isMissedAppointment() && lead.getCount() < 1) { affiliateDetails = "Missed Appointment"; } count++; } } } data.put(index.toString(), new Object[] { lead.getLeadId(), lead.getClient().getName(), lead.getClient().getPhoneNumber(), lead.getClient().getEmailId(), lead.getClient().getCampaignName(), lead.getClient().getPubId(), lead.getClient().getSource(), lead.getClient().getDateCreation(), lead.getClient().getCity(), affiliateDetails, caller, Integer.toString(lead.getCount()), lead.getClient().getInitialComments(), lead.getComments(), lead.getFollowUpDate(), leadDetailsArray[0], dateDetailsArray[0], leadDetailsArray[1], dateDetailsArray[1], leadDetailsArray[2], dateDetailsArray[2], leadDetailsArray[3], dateDetailsArray[3], leadDetailsArray[4], dateDetailsArray[4], leadDetailsArray[5], dateDetailsArray[5], leadDetailsArray[6], dateDetailsArray[6], leadDetailsArray[7], dateDetailsArray[7], leadDetailsArray[8], dateDetailsArray[8], leadDetailsArray[9], dateDetailsArray[9], leadDetailsArray[10], dateDetailsArray[10], leadDetailsArray[11], dateDetailsArray[11], leadDetailsArray[12], dateDetailsArray[12], leadDetailsArray[13], dateDetailsArray[13], leadDetailsArray[14], dateDetailsArray[14], leadDetailsArray[15], dateDetailsArray[15], "", lead.getLeadStatus() }); index++; lead = null; } } list = null; 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); } } out = new FileOutputStream(new File(excelOutputFilePath)); workbook.write(out); out = new FileOutputStream(new File(excelOutputBuildFilePath)); workbook.write(out); flag = true; System.out.println("Excel written successfully.."); } catch (Exception e) { e.printStackTrace(); } finally { try { if (workbook != null) { workbook.close(); } } catch (Exception e) { e.printStackTrace(); } try { if (out != null) { out.close(); } } catch (Exception e) { e.printStackTrace(); } } return flag; }
From source file:com.jubinationre.service.AdminMaintainService.java
public boolean createExcel(List<CallAPIMessage> list) { boolean flag = false; HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("Sample sheet"); CallAPIMessage[] messageArray = new CallAPIMessage[list.size()]; list.toArray(messageArray);//from ww w .j ava 2 s .c om Map<String, Object[]> data = new LinkedHashMap<>(); Integer index = 1; data.put(index.toString(), new Object[] { "CallFrom", "CallTo", "Status", "TrackStatus", "CallType", "DailWhomNumber", "DailCallDuration", "Message", "DateCreated", "AnsweredBy", "StartTime", "EndTime", "DateUpdated", "Duration", "Price", "Direction", "Digits", "Sid", "Uri", "RecordingUrl", "PhoneNumberSid", "AccountSid", "ForwardedFrom", "CallerName", "ParentCallSid" }); index++; for (CallAPIMessage message : messageArray) { data.put(index.toString(), new Object[] { message.getCallFrom(), message.getCallTo(), message.getStatus(), message.getTrackStatus(), message.getCallType(), message.getDailWhomNumber(), message.getDailCallDuration(), message.getMessage(), message.getDateCreated(), message.getAnsweredBy(), message.getStartTime(), message.getEndTime(), message.getDateUpdated(), message.getDuration(), message.getPrice(), message.getDirection(), message.getDigits(), message.getSid(), message.getUri(), message.getRecordingUrl(), message.getPhoneNumberSid(), message.getAccountSid(), message.getForwardedFrom(), message.getCallerName(), message.getParentCallSid() }); index++; } 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); } } try { FileOutputStream out = new FileOutputStream(new File(excelOutputFilePath)); workbook.write(out); out.close(); flag = true; System.out.println("Excel written successfully.."); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return flag; }