List of usage examples for org.apache.poi.hssf.usermodel HSSFWorkbook setSheetName
@Override public void setSheetName(int sheetIx, String name)
From source file:HSSFReadWrite.java
License:Apache License
/** * given a filename this outputs a sample sheet with just a set of * rows/cells./* w ww . j a v a2 s. c o m*/ */ private static void testCreateSampleSheet(String outputFilename) throws IOException { int rownum; HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet s = wb.createSheet(); HSSFCellStyle cs = wb.createCellStyle(); HSSFCellStyle cs2 = wb.createCellStyle(); HSSFCellStyle cs3 = wb.createCellStyle(); HSSFFont f = wb.createFont(); HSSFFont f2 = wb.createFont(); f.setFontHeightInPoints((short) 12); f.setColor((short) 0xA); f.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); f2.setFontHeightInPoints((short) 10); f2.setColor((short) 0xf); f2.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); cs.setFont(f); cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("($#,##0_);[Red]($#,##0)")); cs2.setBorderBottom(HSSFCellStyle.BORDER_THIN); cs2.setFillPattern((short) 1); // fill w fg cs2.setFillForegroundColor((short) 0xA); cs2.setFont(f2); wb.setSheetName(0, "HSSF Test"); for (rownum = 0; rownum < 300; rownum++) { HSSFRow r = s.createRow(rownum); if ((rownum % 2) == 0) { r.setHeight((short) 0x249); } for (int cellnum = 0; cellnum < 50; cellnum += 2) { HSSFCell c = r.createCell(cellnum); c.setCellValue(rownum * 10000 + cellnum + (((double) rownum / 1000) + ((double) cellnum / 10000))); if ((rownum % 2) == 0) { c.setCellStyle(cs); } c = r.createCell(cellnum + 1); c.setCellValue(new HSSFRichTextString("TEST")); // 50 characters divided by 1/20th of a point s.setColumnWidth(cellnum + 1, (int) (50 * 8 / 0.05)); if ((rownum % 2) == 0) { c.setCellStyle(cs2); } } } // draw a thick black border on the row at the bottom using BLANKS rownum++; rownum++; HSSFRow r = s.createRow(rownum); cs3.setBorderBottom(HSSFCellStyle.BORDER_THICK); for (int cellnum = 0; cellnum < 50; cellnum++) { HSSFCell c = r.createCell(cellnum); c.setCellStyle(cs3); } s.addMergedRegion(new CellRangeAddress(0, 3, 0, 3)); s.addMergedRegion(new CellRangeAddress(100, 110, 100, 110)); // end draw thick black border // create a sheet, set its title then delete it s = wb.createSheet(); wb.setSheetName(1, "DeletedSheet"); wb.removeSheetAt(1); // end deleted sheet FileOutputStream out = new FileOutputStream(outputFilename); wb.write(out); out.close(); }
From source file:Console.java
static public void exportToExcel(String sheetName, ArrayList headers, ArrayList data, File outputFile) throws HPSFException { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet(sheetName); int rowIdx = 0; short cellIdx = 0; // Header/*ww w . j a v a2 s. c om*/ HSSFRow hssfHeader = sheet.createRow(rowIdx); HSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); for (Iterator cells = headers.iterator(); cells.hasNext();) { HSSFCell hssfCell = hssfHeader.createCell(cellIdx++); hssfCell.setCellStyle(cellStyle); hssfCell.setCellValue((String) cells.next()); } // Data rowIdx = 1; for (Iterator rows = data.iterator(); rows.hasNext();) { ArrayList row = (ArrayList) rows.next(); HSSFRow hssfRow = sheet.createRow(rowIdx++); cellIdx = 0; for (Iterator cells = row.iterator(); cells.hasNext();) { HSSFCell hssfCell = hssfRow.createCell(cellIdx++); Object o = cells.next(); if ("class java.lang.Double".equals(o.getClass().toString())) { hssfCell.setCellValue((Double) o); } else { hssfCell.setCellValue((String) o); } } } wb.setSheetName(0, sheetName); try { FileOutputStream outs = new FileOutputStream(outputFile); wb.write(outs); outs.close(); // System.out.println("Archivo creado correctamente en " + outputFile.getAbsolutePath()); } catch (IOException e) { e.printStackTrace(); throw new HPSFException(e.getMessage()); } }
From source file:com.mmj.app.common.file.ExcelUtils.java
License:Open Source License
/** * excelrow?IExcel.initHSSRow//w w w . j a v a 2 s.co m * * @param response * @param list * @param name * @param iExcel * @param headTitle * @return */ public static <T> HSSFWorkbook buildExcel(List<T> list, String name, IExcel<T> iExcel, String... headTitle) { if (list == null || list.size() == 0) { log.error("ExcelUtils buildExcel List<T>:list is null,name={}", name); return null; } if (iExcel == null || Argument.isEmptyArray(headTitle)) { return new HSSFWorkbook(); } String xlsName = name + "_" + DateViewTools.format(new Date(), "yyyy_MM_dd_HH_mm"); // HSSFWorkbook workbook = new HSSFWorkbook(); // HSSFSheet sheet = workbook.createSheet(); workbook.setSheetName(0, xlsName); for (int i = 0; i < headTitle.length; i++) { // ? sheet.setColumnWidth(i, 17 * 256); } HSSFRow rowTitle = sheet.createRow(0); HSSFCell cell = null; for (int i = 0; i < headTitle.length; i++) { // ? cell = rowTitle.createCell(i); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue(headTitle[i]); } // row iExcel.initHSSRow(list, sheet); return workbook; }
From source file:com.selfsoft.business.service.impl.TbBusinessBalanceServiceImpl.java
public void printTbBusinessBalanceTemplate(OutputStream os, String tpl, Long id, String companyName) { // ??// w w w.ja v a 2 s . c om TbBusinessBalance tbBusinessBalance = this.findById(id); // ? TbFixEntrust tbFixEntrust = tbFixEntrustService.findById(tbBusinessBalance.getTbFixEntrust().getId()); // ? TbCustomer tbCustomer = tbCustomerService.findById(tbFixEntrust.getTbCustomer().getId()); // ? TbCarInfo tbCarInfo = tbCarInfoService.findById(tbFixEntrust.getTbCarInfo().getId()); // ?? TmCompany tmCompany = tmCompanyService.acquireUniqueTmCompany(); // ? List<TbFixEntrustContent> tbFixEntrustContentList = tbFixEntrustContentService .findTbFixEnTrustContentListByTbFixEntrustId(tbFixEntrust.getId()); List<TbFixEntrustContent> tbFixEntrustContentListPage = new ArrayList<TbFixEntrustContent>(); List<TbFixEntrustContent> tbFixEntrustContentListTemp = new ArrayList<TbFixEntrustContent>(); List<TbFixEntrustContent> tbFixEntrustContentListAdd = new ArrayList<TbFixEntrustContent>(); if (null != tbFixEntrustContentList && tbFixEntrustContentList.size() > 0) { for (int i = 0; i < tbFixEntrustContentList.size(); i++) { boolean flag = false; if (tbFixEntrustContentListTemp.size() == 0) { tbFixEntrustContentListTemp.add(tbFixEntrustContentList.get(i)); } else { if (tbFixEntrustContentListTemp.size() > 1) { for (TbFixEntrustContent _tbFixEntrustContent : tbFixEntrustContentListTemp) { if (_tbFixEntrustContent.getStationName() .equals(tbFixEntrustContentList.get(i).getStationName()) && _tbFixEntrustContent.getTbWorkingInfo().getId() .equals(tbFixEntrustContentList.get(i).getTbWorkingInfo().getId()) && _tbFixEntrustContent.getFreesymbol() .equals(tbFixEntrustContentList.get(i).getFreesymbol()) ) { flag = true; break; } } } } if (flag) { continue; } else { tbFixEntrustContentListTemp.add(tbFixEntrustContentList.get(i)); } TbFixEntrustContent temp = tbFixEntrustContentList.get(i); BigDecimal d = new BigDecimal(temp.getFixHourAll()); BigDecimal d2 = new BigDecimal(temp.getFixHour()); for (int j = i + 1; j < tbFixEntrustContentList.size(); j++) { if (temp.getStationName().equals(tbFixEntrustContentList.get(j).getStationName()) && temp.getTbWorkingInfo().getId() .equals(tbFixEntrustContentList.get(j).getTbWorkingInfo().getId()) && temp.getFreesymbol().equals(tbFixEntrustContentList.get(j).getFreesymbol())) { d = d.add(new BigDecimal(tbFixEntrustContentList.get(j).getFixHourAll())); d2 = d2.add(new BigDecimal(tbFixEntrustContentList.get(j).getFixHour())); } } temp.setFixHourAll(d.doubleValue()); temp.setFixHour(d2.doubleValue()); if (!temp.getFreesymbol().equals(1d) || !temp.getFixHourAll().equals(0d)) { tbFixEntrustContentListAdd.add(temp); } } } // ?? List<TbMaintianVo> maintianvos = tbMaintainPartContentService .getTbMaintianDetailVosByEntrustId(tbFixEntrust.getId(), Constants.BALANCE_ALL); // ? List<TmStockOutDetVo> tmStockOutDetVos = tmStockOutService .getSellDetailByEntrustCode(tbFixEntrust.getEntrustCode(), Constants.BALANCE_ALL); // List<TbBusinessBalanceItem> tbBusinessBalanceItemList = tbBusinessBalanceItemService .findGroupTbBusinessBalanceItemListByTbBusinessBalanceId(tbBusinessBalance.getId()); // ??? if (null == maintianvos) { maintianvos = new ArrayList<TbMaintianVo>(); } if (null != tmStockOutDetVos && tmStockOutDetVos.size() > 0) { for (TmStockOutDetVo tmStockOutDetVo : tmStockOutDetVos) { TbMaintianVo tbMaintianVo = new TbMaintianVo(); tbMaintianVo.setPartId(tmStockOutDetVo.getPartinfoId()); tbMaintianVo.setHouseName(tmStockOutDetVo.getHouseName()); tbMaintianVo.setPartCode(tmStockOutDetVo.getPartCode()); tbMaintianVo.setPartName(tmStockOutDetVo.getPartName()); tbMaintianVo.setUnitName(tmStockOutDetVo.getUnitName()); tbMaintianVo.setPrice(tmStockOutDetVo.getPrice()); tbMaintianVo.setPartQuantity(tmStockOutDetVo.getQuantity()); tbMaintianVo.setTotal(tmStockOutDetVo.getTotal()); tbMaintianVo.setIsFree(tmStockOutDetVo.getIsFree()); tbMaintianVo.setProjectType(tmStockOutDetVo.getProjectType()); tbMaintianVo.setZl(tmStockOutDetVo.getZl()); tbMaintianVo.setXmlx(tmStockOutDetVo.getXmlx()); maintianvos.add(tbMaintianVo); } } /** * add by ccr 2010-12-18 */ List<TbMaintianVo> maintianvosTemp = new ArrayList<TbMaintianVo>(); List<TbMaintianVo> maintianvosAdd = new ArrayList<TbMaintianVo>(); if (maintianvos.size() > 0) { for (int i = 0; i < maintianvos.size(); i++) { boolean flag = false; if (maintianvosTemp.size() == 0) { maintianvosTemp.add(maintianvos.get(i)); } else { if (maintianvosTemp.size() > 1) { int l = 0; for (TbMaintianVo _tbMaintianVo : maintianvosTemp) { if (_tbMaintianVo.getPartId().equals(maintianvos.get(i).getPartId()) && _tbMaintianVo.getIsFree().equals(maintianvos.get(i).getIsFree()) && _tbMaintianVo.getPrice().equals(maintianvos.get(i).getPrice())) { // maintianvosTemp.set(l, maintianvos.get(i)); flag = true; break; } l++; } } } if (flag) { continue; } else { maintianvosTemp.add(maintianvos.get(i)); } TbMaintianVo temp = maintianvos.get(i); BigDecimal d1 = new BigDecimal(temp.getPartQuantity()); BigDecimal d2 = new BigDecimal(temp.getTotal()); for (int j = i + 1; j < maintianvos.size(); j++) { if (temp.getPartId().equals(maintianvos.get(j).getPartId()) && temp.getIsFree().equals(maintianvos.get(j).getIsFree()) && temp.getPrice().equals(maintianvos.get(j).getPrice())) { temp.setPrice(maintianvos.get(j).getPrice()); d1 = d1.add(new BigDecimal(maintianvos.get(j).getPartQuantity())); d2 = d2.add(new BigDecimal(maintianvos.get(j).getTotal())); } } temp.setPartQuantity(d1.doubleValue()); temp.setTotal(d2.doubleValue()); if (!temp.getIsFree().equals(1L) || !temp.getPartQuantity().equals(0d)) { /* * temp.setPrice(new BigDecimal(temp.getTotal()).divide(new * BigDecimal(temp.getPartQuantity()),2, * BigDecimal.ROUND_HALF_UP).setScale(2, * BigDecimal.ROUND_HALF_UP).doubleValue()); */ maintianvosAdd.add(temp); } } } int fixSize = (tbFixEntrustContentListAdd == null ? 0 : tbFixEntrustContentListAdd.size()); int partSize = (maintianvosAdd == null ? 0 : maintianvosAdd.size()); try { HSSFWorkbook workbook = new HSSFWorkbook(this.getClass().getResourceAsStream(tpl)); HSSFSheet sheet = workbook.getSheetAt(0); HSSFCellStyle style = workbook.createCellStyle(); style.setWrapText(true); style.setAlignment(HSSFCellStyle.ALIGN_LEFT); style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFFont font = workbook.createFont(); font.setFontName(""); font.setFontHeightInPoints((short) 9); style.setFont(font); HSSFCellStyle styleRight = workbook.createCellStyle(); styleRight.setWrapText(true); styleRight.setAlignment(HSSFCellStyle.ALIGN_RIGHT); styleRight.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); styleRight.setFont(font); HSSFCellStyle styleBorderThinAll = workbook.createCellStyle(); styleBorderThinAll.setBorderLeft(HSSFCellStyle.BORDER_THIN); styleBorderThinAll.setBorderRight(HSSFCellStyle.BORDER_THIN); styleBorderThinAll.setBorderTop(HSSFCellStyle.BORDER_THIN); styleBorderThinAll.setBorderBottom(HSSFCellStyle.BORDER_THIN); styleBorderThinAll.setWrapText(true); styleBorderThinAll.setAlignment(HSSFCellStyle.ALIGN_LEFT); styleBorderThinAll.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); styleBorderThinAll.setFont(font); HSSFCellStyle styleBorderThickLeft = workbook.createCellStyle(); styleBorderThickLeft.setBorderLeft(HSSFCellStyle.BORDER_THICK); styleBorderThickLeft.setBorderRight(HSSFCellStyle.BORDER_THIN); styleBorderThickLeft.setBorderTop(HSSFCellStyle.BORDER_THIN); styleBorderThickLeft.setBorderBottom(HSSFCellStyle.BORDER_THIN); styleBorderThickLeft.setWrapText(true); styleBorderThickLeft.setAlignment(HSSFCellStyle.ALIGN_LEFT); styleBorderThickLeft.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); styleBorderThickLeft.setFont(font); HSSFCellStyle styleBorderThickRight = workbook.createCellStyle(); styleBorderThickRight.setBorderRight(HSSFCellStyle.BORDER_THICK); styleBorderThickRight.setBorderLeft(HSSFCellStyle.BORDER_THIN); styleBorderThickRight.setBorderTop(HSSFCellStyle.BORDER_THIN); styleBorderThickRight.setBorderBottom(HSSFCellStyle.BORDER_THIN); styleBorderThickRight.setWrapText(true); styleBorderThickRight.setAlignment(HSSFCellStyle.ALIGN_LEFT); styleBorderThickRight.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); styleBorderThickRight.setFont(font); HSSFCellStyle styleBorderThinAllCenter = workbook.createCellStyle(); styleBorderThinAllCenter.setBorderLeft(HSSFCellStyle.BORDER_THIN); styleBorderThinAllCenter.setBorderRight(HSSFCellStyle.BORDER_THIN); styleBorderThinAllCenter.setBorderTop(HSSFCellStyle.BORDER_THIN); styleBorderThinAllCenter.setBorderBottom(HSSFCellStyle.BORDER_THIN); styleBorderThinAllCenter.setWrapText(true); styleBorderThinAllCenter.setAlignment(HSSFCellStyle.ALIGN_CENTER); styleBorderThinAllCenter.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); styleBorderThinAllCenter.setFont(font); HSSFCellStyle styleBorderThickLeftCenter = workbook.createCellStyle(); styleBorderThickLeftCenter.setBorderLeft(HSSFCellStyle.BORDER_THICK); styleBorderThickLeftCenter.setBorderRight(HSSFCellStyle.BORDER_THIN); styleBorderThickLeftCenter.setBorderTop(HSSFCellStyle.BORDER_THIN); styleBorderThickLeftCenter.setBorderBottom(HSSFCellStyle.BORDER_THIN); styleBorderThickLeftCenter.setWrapText(true); styleBorderThickLeftCenter.setAlignment(HSSFCellStyle.ALIGN_CENTER); styleBorderThickLeftCenter.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); styleBorderThickLeftCenter.setFont(font); HSSFCellStyle styleBorderThickRightCenter = workbook.createCellStyle(); styleBorderThickRightCenter.setBorderRight(HSSFCellStyle.BORDER_THICK); styleBorderThickRightCenter.setBorderLeft(HSSFCellStyle.BORDER_THIN); styleBorderThickRightCenter.setBorderTop(HSSFCellStyle.BORDER_THIN); styleBorderThickRightCenter.setBorderBottom(HSSFCellStyle.BORDER_THIN); styleBorderThickRightCenter.setWrapText(true); styleBorderThickRightCenter.setAlignment(HSSFCellStyle.ALIGN_CENTER); styleBorderThickRightCenter.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); styleBorderThickRightCenter.setFont(font); HSSFCellStyle styleCenter = workbook.createCellStyle(); styleCenter.setWrapText(true); styleCenter.setAlignment(HSSFCellStyle.ALIGN_CENTER); styleCenter.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); styleCenter.setFont(font); HSSFRow row = null; HSSFCell cell = null; row = sheet.getRow(2); cell = row.getCell(4); // cell.setCellStyle(style); if ("dfbz".equals(companyName)) { cell.setCellValue(Constants.getCompanyMap().get("dfbzCode")); } else if ("xtl".equals(companyName)) { cell.setCellValue(Constants.getCompanyMap().get("xtlCode")); } row = sheet.getRow(2); cell = row.getCell(17); if ("xtl".equals(companyName)) { cell.setCellValue(/* tmCompany.getCompanyName() */"?"); } else { cell.setCellValue(tmCompany.getCompanyName()); } row = sheet.getRow(2); cell = row.getCell(33); cell.setCellValue(tmCompany.getCompanyPhone() == null ? "" : tmCompany.getCompanyPhone()); row = sheet.getRow(4); cell = row.getCell(4); if ("xtl".equals(companyName)) { cell.setCellValue(""); } else { cell.setCellValue(tmCompany.getCompanyZipCode() == null ? "" : tmCompany.getCompanyZipCode()); } row = sheet.getRow(4); cell = row.getCell(17); cell.setCellValue(tmCompany.getCompanyAddress() == null ? "" : tmCompany.getCompanyAddress()); row = sheet.getRow(4); cell = row.getCell(33); cell.setCellValue(tmCompany.getCompanyFax() == null ? "" : tmCompany.getCompanyFax()); row = sheet.getRow(10); cell = row.getCell(2); // cell.setCellStyle(style); String entrustCode = tbFixEntrust.getEntrustCode(); String[] es = entrustCode.split("-"); String newCode = "RO" + es[0].substring(2, 6) + es[1]; cell.setCellValue(newCode); row = sheet.getRow(10); cell = row.getCell(24); // cell.setCellStyle(style); cell.setCellValue((tbFixEntrust.getTmUser().getUserRealName() == null || "".equals(tbFixEntrust.getTmUser().getUserRealName())) ? tbFixEntrust.getTmUser().getUserName() : tbFixEntrust.getTmUser().getUserRealName()); row = sheet.getRow(10); cell = row.getCell(40); // cell.setCellStyle(styleCenter); cell.setCellValue( CommonMethod.parseDateToString(tbBusinessBalance.getBananceDate(), "yyyy-MM-dd HH:mm")); row = sheet.getRow(8); cell = row.getCell(40); // cell.setCellStyle(styleCenter); cell.setCellValue(CommonMethod.parseDateToString(tbFixEntrust.getFixDate(), "yyyy-MM-dd HH:mm")); row = sheet.getRow(12); cell = row.getCell(4); cell.setCellValue(tbCustomer.getCustomerName()); row = sheet.getRow(12); cell = row.getCell(24); cell.setCellValue(tbCarInfo.getLicenseCode()); row = sheet.getRow(12); cell = row.getCell(41); cell.setCellValue(tbCarInfo.getTmCarModelType().getModelName()); row = sheet.getRow(14); cell = row.getCell(4); cell.setCellValue(tbCustomer.getTelephone() == null ? "" : tbCustomer.getTelephone()); row = sheet.getRow(18); cell = row.getCell(12); cell.setCellValue(tbCustomer.getTelephone() == null ? "" : tbCustomer.getTelephone()); row = sheet.getRow(14); cell = row.getCell(24); cell.setCellValue(tbCarInfo.getChassisCode()); row = sheet.getRow(16); cell = row.getCell(4); cell.setCellValue(tbCustomer.getAddress() == null ? "" : tbCustomer.getAddress()); row = sheet.getRow(16); cell = row.getCell(24); cell.setCellValue(CommonMethod.parseDateToString(tbCarInfo.getPurchaseDate(), "yyyy-MM-dd")); row = sheet.getRow(16); cell = row.getCell(41); if ("xtl".equals(companyName)) { cell.setCellValue( tbFixEntrust.getEnterStationKilo() == null ? "" : new BigDecimal(tbFixEntrust.getEnterStationKilo()) .divide(new BigDecimal("1.00"), 0, BigDecimal.ROUND_HALF_UP).toString() + " Km"); } else { cell.setCellValue( tbFixEntrust.getEnterStationKilo() == null ? "" : new BigDecimal(tbFixEntrust.getEnterStationKilo()) .divide(new BigDecimal("1.00"), 0, BigDecimal.ROUND_HALF_UP).toString() + " Km"); } row = sheet.getRow(18); cell = row.getCell(4); cell.setCellValue(tbCustomer.getContractPerson() == null ? "" : tbCustomer.getContractPerson()); row = sheet.getRow(18); cell = row.getCell(24); cell.setCellValue(tbCarInfo.getEngineCode() == null ? "" : tbCarInfo.getEngineCode()); row = sheet.getRow(18); cell = row.getCell(41); cell.setCellValue(tbCarInfo.getColor() == null ? "" : tbCarInfo.getColor()); /* * if (null != tbBusinessBalanceItemList && * tbBusinessBalanceItemList.size() > 0) { * * for (TbBusinessBalanceItem tbBusinessBalanceItem : * tbBusinessBalanceItemList) { * * if ("XLCLF".equals(tbBusinessBalanceItem .getBalanceItemCode())) * { * * row = sheet.getRow(77); * * cell = row.getCell(24); * * cell.setCellValue(new BigDecimal(tbBusinessBalanceItem * .getBalanceItemTotal()).divide( new BigDecimal("1.00"), 2, * BigDecimal.ROUND_HALF_UP).toString()); * * continue; } * * if ("XLGSF".equals(tbBusinessBalanceItem .getBalanceItemCode())) * { * * row = sheet.getRow(75); * * cell = row.getCell(24); * * cell.setCellValue(new BigDecimal(tbBusinessBalanceItem * .getBalanceItemTotal()).divide( new BigDecimal("1.00"), 2, * BigDecimal.ROUND_HALF_UP).toString()); * * continue; } * * if ("ZJE" .equals(tbBusinessBalanceItem.getBalanceItemCode())) { * * row = sheet.getRow(81); * * cell = row.getCell(24); * * cell.setCellValue(new BigDecimal(tbBusinessBalanceItem * .getBalanceItemTotal()).divide( new BigDecimal("1.00"), 2, * BigDecimal.ROUND_HALF_UP).toString()); * * continue; } * * } * * row = sheet.getRow(79); * * cell = row.getCell(24); * * cell.setCellValue("0.00"); * * } */ BigDecimal d_f_w = new BigDecimal("0.00"); BigDecimal d_f_p = new BigDecimal("0.00"); BigDecimal d_f_i = new BigDecimal("0.00"); BigDecimal d_f_c = new BigDecimal("0.00"); if (fixSize > 0) { for (int i = 0; i < fixSize; i++) { TbFixEntrustContent t = tbFixEntrustContentListAdd.get(i); if ("W".equals(t.getZl())) { d_f_w = d_f_w.add(new BigDecimal(t.getFixHourAll())); } else if ("P".equals(t.getZl())) { d_f_p = d_f_p.add(new BigDecimal(t.getFixHourAll())); } else if ("I".equals(t.getZl())) { d_f_i = d_f_i.add(new BigDecimal(t.getFixHourAll())); } else if ("C".equals(t.getZl())) { d_f_c = d_f_c.add(new BigDecimal(t.getFixHourAll())); } } } BigDecimal d_p_w = new BigDecimal("0.00"); BigDecimal d_p_p = new BigDecimal("0.00"); BigDecimal d_p_i = new BigDecimal("0.00"); BigDecimal d_p_c = new BigDecimal("0.00"); if (partSize > 0) { for (int i = 0; i < partSize; i++) { TbMaintianVo t = maintianvosAdd.get(i); if ("W".equals(t.getZl())) { d_p_w = d_p_w.add(new BigDecimal(t.getTotal())); } else if ("P".equals(t.getZl())) { d_p_p = d_p_p.add(new BigDecimal(t.getTotal())); } else if ("I".equals(t.getZl())) { d_p_i = d_p_i.add(new BigDecimal(t.getTotal())); } else if ("C".equals(t.getZl())) { d_p_c = d_p_c.add(new BigDecimal(t.getTotal())); } } } row = sheet.getRow(75); cell = row.getCell(6); cell.setCellValue(d_f_w.divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); row = sheet.getRow(77); cell = row.getCell(6); cell.setCellValue(d_p_w.divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); row = sheet.getRow(79); cell = row.getCell(6); cell.setCellValue("0.00"); row = sheet.getRow(81); cell = row.getCell(6); cell.setCellValue( d_f_w.add(d_p_w).divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); row = sheet.getRow(75); cell = row.getCell(12); cell.setCellValue(d_f_p.divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); row = sheet.getRow(77); cell = row.getCell(12); cell.setCellValue(d_p_p.divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); row = sheet.getRow(79); cell = row.getCell(12); cell.setCellValue("0.00"); row = sheet.getRow(81); cell = row.getCell(12); cell.setCellValue( d_f_p.add(d_p_p).divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); row = sheet.getRow(75); cell = row.getCell(18); cell.setCellValue(d_f_i.divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); row = sheet.getRow(77); cell = row.getCell(18); cell.setCellValue(d_p_i.divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); row = sheet.getRow(79); cell = row.getCell(18); cell.setCellValue("0.00"); row = sheet.getRow(81); cell = row.getCell(18); cell.setCellValue( d_f_i.add(d_p_i).divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); row = sheet.getRow(75); cell = row.getCell(24); cell.setCellValue(d_f_c.divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); row = sheet.getRow(77); cell = row.getCell(24); cell.setCellValue(d_p_c.divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); row = sheet.getRow(79); cell = row.getCell(24); cell.setCellValue("0.00"); row = sheet.getRow(81); cell = row.getCell(24); cell.setCellValue( d_f_c.add(d_p_c).divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); Double wt = tbBusinessBalance.getWorkingHourTotalAll() == null ? 0d : tbBusinessBalance.getWorkingHourTotalAll(); Double wf = tbBusinessBalance.getWorkingHourFavourRate() == null ? 0d : tbBusinessBalance.getWorkingHourFavourRate(); Double pt = tbBusinessBalance.getFixPartTotalAll() == null ? 0d : tbBusinessBalance.getFixPartTotalAll(); Double pf = tbBusinessBalance.getFixPartFavourRate() == null ? 0d : tbBusinessBalance.getFixPartFavourRate(); Double st = tbBusinessBalance.getSolePartTotalAll() == null ? 0d : tbBusinessBalance.getSolePartTotalAll(); Double sf = tbBusinessBalance.getSolePartFavourRate() == null ? 0d : tbBusinessBalance.getSolePartFavourRate(); BigDecimal fixF = new BigDecimal(wt).divide(new BigDecimal(1 - wf), 2, BigDecimal.ROUND_HALF_UP) .multiply(new BigDecimal(wf)); BigDecimal partF = new BigDecimal(pt).divide(new BigDecimal(1 - pf), 2, BigDecimal.ROUND_HALF_UP) .multiply(new BigDecimal(pf)); BigDecimal soleF = new BigDecimal(st).divide(new BigDecimal(1 - sf), 2, BigDecimal.ROUND_HALF_UP) .multiply(new BigDecimal(sf)); row = sheet.getRow(83); cell = row.getCell(4); // cell.setCellStyle(styleCenter); cell.setCellValue(fixF.add(partF).add(soleF).divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP) .toString()); row = sheet.getRow(83); cell = row.getCell(14); // cell.setCellStyle(styleCenter); cell.setCellValue(new BigDecimal(tbBusinessBalance.getPayedAmount()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); row = sheet.getRow(68); cell = row.getCell(40); // cell.setCellStyle(styleCenter); cell.setCellValue(CommonMethod .parseDateToString(tbBusinessBalance.getTbFixEntrust().getRemindMaintainDate(), "yyyy-MM-dd")); row = sheet.getRow(70); cell = row.getCell(40); // cell.setCellStyle(styleCenter); cell.setCellValue(tbBusinessBalance.getTbFixEntrust().getRemindMaintainKilo() == null ? "" : new BigDecimal(tbBusinessBalance.getTbFixEntrust().getRemindMaintainKilo()) .divide(new BigDecimal("1.00"), 0, BigDecimal.ROUND_HALF_UP) + ""); row = sheet.getRow(77); cell = row.getCell(30); // cell.setCellStyle(styleCenter); cell.setCellValue(tbBusinessBalance.getTbFixEntrust().getRemark()); ByteArrayOutputStream byteArrayOutImgLion = new ByteArrayOutputStream(); String pic = ""; if ("dfbz".equals(companyName)) { pic = "/lion_jsd.png"; } else if ("xtl".equals(companyName)) { pic = "/xtl_jsd.png"; } BufferedImage bufferImgLion = ImageIO.read(this.getClass().getResourceAsStream(pic)); ImageIO.write(bufferImgLion, "png", byteArrayOutImgLion); HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); HSSFClientAnchor anchorLion = new HSSFClientAnchor(0, 0, 1023, 200, (short) 41, 0, (short) 46, 7); patriarch.createPicture(anchorLion, workbook.addPicture(byteArrayOutImgLion.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); /* * int maxSize = 19; * * int maxFixSize = (fixSize > 19 ? 19 : fixSize); * * int maxPartSize = maxSize - maxFixSize > partSize ? partSize : * maxSize - maxFixSize; * * int partStartRow = (fixSize == 0 ? 21 : 21 + maxFixSize * 2 + 4); * * int partStartRowClone = ((fixSize - maxFixSize) == 0 ? 21 : 21 + * (fixSize - maxFixSize) * 2 + 4); * * int minBlank = 9; * * if ((fixSize + partSize) > 17) { * * HSSFSheet sheetClone = workbook.cloneSheet(0); * * HSSFRow rowClone = sheetClone.getRow(87); * * HSSFCell cellClone = rowClone.getCell(34); * * cellClone.setCellValue("2 2 "); * * HSSFPatriarch patriarchClone = sheetClone * .createDrawingPatriarch(); * * HSSFClientAnchor anchorLionClone = new HSSFClientAnchor(0, 0, * 1023, 200, (short) 41, 0, (short) 47, 8); * * patriarchClone.createPicture(anchorLionClone, workbook * .addPicture(byteArrayOutImgLion.toByteArray(), * HSSFWorkbook.PICTURE_TYPE_PNG)); * * if ((fixSize - maxFixSize) > 0) { * * * sheetClone.addMergedRegion(new Region(21, (short) 0, 21, (short) * 49)); * * sheetClone.addMergedRegion(new Region(21, (short) 0, 21, (short) * 0)); * * * sheetClone.addMergedRegion(new CellRangeAddress(21, 21, 0, 49)); * * rowClone = sheetClone.getRow(21); * * cellClone = rowClone.getCell(0); * * // cellClone.setCellStyle(style); * * cellClone.setCellValue(""); * * cellClone.setCellStyle(styleBorderThickLeft); * * rowClone = sheetClone.getRow(21); * * cellClone = rowClone.getCell(0); * * cellClone.setCellStyle(styleBorderThickLeft); * * rowClone = sheetClone.getRow(24); * * cellClone = rowClone.getCell(0); * * cellClone.setCellStyle(styleBorderThickLeftCenter); * * rowClone = sheetClone.getRow(23); * * cellClone = rowClone.getCell(0); * * // cellClone.setCellStyle(styleCenter); * * cellClone.setCellStyle(styleBorderThickLeftCenter); * * cellClone.setCellValue("??"); * * cellClone = rowClone.getCell(2); * * cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue("?"); * * cellClone = rowClone.getCell(10); * * cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue(""); * * cellClone = rowClone.getCell(21); * * cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue("?"); * * cellClone = rowClone.getCell(24); * * cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue(""); * * cellClone = rowClone.getCell(30); * * cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue(""); * * cellClone = rowClone.getCell(34); * * cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue("?"); * * cellClone = rowClone.getCell(40); * * cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue(""); * * cellClone = rowClone.getCell(44); * * cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue(""); * * for (int i = 0; i < (fixSize - maxFixSize); i++) { * * TbFixEntrustContent tbFixEntrustContent = * tbFixEntrustContentListAdd .get(i + maxFixSize); * * rowClone = sheetClone.getRow(25 + i * 2); * * cellClone = rowClone.getCell(0); * * // cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue(i + 1); * * cellClone = rowClone.getCell(2); * * // cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue(tbFixEntrustContent .getStationCode()); * * cellClone = rowClone.getCell(10); * * // cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue(tbFixEntrustContent .getStationName()); * * cellClone = rowClone.getCell(21); * * // cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue(tbFixEntrustContent.getZl()); * * cellClone = rowClone.getCell(24); * * // cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue(tbFixEntrustContent .getProjectType()); * * cellClone = rowClone.getCell(30); * * // cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue(new BigDecimal( * tbFixEntrustContent.getFixHour()).divide( new BigDecimal("1.00"), * 2, BigDecimal.ROUND_HALF_UP).toString()); * * cellClone = rowClone.getCell(34); * * // cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue(new BigDecimal( * tbFixEntrustContent.getWorkingHourPrice()) .divide(new * BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); * * cellClone = rowClone.getCell(40); * * // cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue(new BigDecimal(tbBusinessBalance * .getWorkingHourFavourRate()).divide( new BigDecimal("1.00"), 2, * BigDecimal.ROUND_HALF_UP).toString()); * * cellClone = rowClone.getCell(44); * * // cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue(new BigDecimal( * tbFixEntrustContent.getFixHourAll()).divide( new * BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); } * * } * * if ((partSize - maxPartSize) > 0) { * * * sheetClone.addMergedRegion(new Region(partStartRowClone, (short) * 0, partStartRowClone, (short) 49)); * * sheetClone.addMergedRegion(new Region(partStartRowClone, (short) * 0, partStartRowClone, (short) 49)); * * * sheetClone.addMergedRegion(new CellRangeAddress( * partStartRowClone, partStartRowClone, 0, 49)); * * rowClone = sheetClone.getRow(partStartRowClone); * * cellClone = rowClone.getCell(0); * * // cellClone.setCellStyle(style); * * cellClone.setCellStyle(styleBorderThickLeft); * * cellClone.setCellValue(""); * * rowClone = sheetClone.getRow(partStartRowClone + 1); * * cellClone = rowClone.getCell(0); * * cellClone.setCellStyle(styleBorderThickLeft); * * rowClone = sheetClone.getRow(partStartRowClone + 2 + 1); * * cellClone = rowClone.getCell(0); * * cellClone.setCellStyle(styleBorderThickLeftCenter); * * rowClone = sheetClone.getRow(partStartRowClone + 2); * * cellClone = rowClone.getCell(0); * * // cellClone.setCellStyle(styleCenter); * cellClone.setCellStyle(styleBorderThickLeftCenter); * * cellClone.setCellValue("??"); * * cellClone = rowClone.getCell(2); * * cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue("?"); * * cellClone = rowClone.getCell(10); * * cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue("??"); * * cellClone = rowClone.getCell(21); * * cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue("?"); * * cellClone = rowClone.getCell(24); * * cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue(""); * * cellClone = rowClone.getCell(30); * * cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue("?"); * * cellClone = rowClone.getCell(34); * * cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue("?"); * * cellClone = rowClone.getCell(40); * * cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue(""); * * cellClone = rowClone.getCell(44); * * cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue(""); * * for (int i = 0; i < (partSize - maxPartSize); i++) { * * TbMaintianVo tbMaintianVo = maintianvosAdd.get(i + maxPartSize); * * rowClone = sheetClone.getRow(partStartRowClone + 4 + i 2); * * if(null == rowClone) break; * * cellClone = rowClone.getCell(0); * * // cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue(i + 1); * * cellClone = rowClone.getCell(2); * * // cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue(tbMaintianVo.getPartCode()); * * cellClone = rowClone.getCell(10); * * // cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue(tbMaintianVo.getPartName()); * * cellClone = rowClone.getCell(21); * * // cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue(tbMaintianVo.getZl()); * * cellClone = rowClone.getCell(24); * * // cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue(tbMaintianVo.getProjectType()); * * cellClone = rowClone.getCell(30); * * cellClone.setCellStyle(styleRight); * * cellClone.setCellValue(new BigDecimal(tbMaintianVo * .getPartQuantity()).divide( new BigDecimal("1.00"), 2, * BigDecimal.ROUND_HALF_UP).toString()); * * cellClone = rowClone.getCell(34); * * // cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue(new BigDecimal(tbMaintianVo * .getPrice()).divide(new BigDecimal("1.00"), 2, * BigDecimal.ROUND_HALF_UP).toString()); * * cellClone = rowClone.getCell(40); * * // .setCellStyle(styleCenter); * * cellClone.setCellValue(new BigDecimal(tbBusinessBalance * .getFixPartFavourRate()).divide( new BigDecimal("1.00"), 2, * BigDecimal.ROUND_HALF_UP).toString()); * * cellClone = rowClone.getCell(44); * * // cellClone.setCellStyle(styleCenter); * * cellClone .setCellValue(new BigDecimal(tbMaintianVo * .getPartQuantity()) .multiply( new BigDecimal(tbMaintianVo * .getPrice())) .divide(new BigDecimal("1.00"), 2, * BigDecimal.ROUND_HALF_UP) .toString()); } * * } * * int attachStartRowClone = 21; * * if ((fixSize - maxFixSize + partSize - maxPartSize) <= 17) { * * if ((fixSize - maxFixSize) != 0 && (partSize - maxPartSize) == 0 * && (fixSize - maxFixSize) < 18) { * * attachStartRowClone = 21 + 2 + 2 + (fixSize - maxFixSize) * 2; * * } * * if ((partSize - maxPartSize) != 0 && (fixSize - maxFixSize) == 0 * && (partSize - maxPartSize) < 18) { * * attachStartRowClone = 21 + 2 + 2 + 2 + (partSize - maxPartSize) * * 2; } * * if ((fixSize - maxFixSize) != 0 && (partSize - maxPartSize) != 0 * && (fixSize - maxFixSize + partSize - maxPartSize < 18)) { * * attachStartRowClone = 21 + 2 + 2 + 2 + 2 + (fixSize - maxFixSize) * * 2 + (partSize - maxPartSize) * 2; * * } * * * sheetClone.addMergedRegion(new Region(attachStartRowClone, * (short) 0, attachStartRowClone, (short) 49)); * * sheetClone.addMergedRegion(new Region(attachStartRowClone, * (short) 0, attachStartRowClone, (short) 49)); * * * sheetClone.addMergedRegion(new CellRangeAddress( * attachStartRowClone, attachStartRowClone, 0, 49)); * * rowClone = sheetClone.getRow(attachStartRowClone); * * cellClone = rowClone.getCell(0); * * // cellClone.setCellStyle(style); * * cellClone.setCellStyle(styleBorderThickLeft); * * cellClone.setCellValue(""); * * rowClone = sheetClone.getRow(attachStartRowClone + 1); * * cellClone = rowClone.getCell(0); * * cellClone.setCellStyle(styleBorderThickLeft); * * rowClone = sheetClone.getRow(attachStartRowClone + 2 + 1); * * cellClone = rowClone.getCell(0); * * cellClone.setCellStyle(styleBorderThickLeftCenter); * * rowClone = sheetClone.getRow(attachStartRowClone + 2); * * cellClone = rowClone.getCell(0); * * cellClone.setCellStyle(styleBorderThickLeftCenter); * * cellClone.setCellValue("??"); * * if ("dfbz".equals(companyName)) { * * cellClone = rowClone.getCell(10); * * cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue("??"); * * cellClone = rowClone.getCell(21); * * cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue("?"); * * cellClone = rowClone.getCell(24); * * cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue(""); * * cellClone = rowClone.getCell(30); * * cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue("?"); * * cellClone = rowClone.getCell(34); * * cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue("?"); * * cellClone = rowClone.getCell(40); * * cellClone.setCellStyle(styleCenter); * * } else if ("xtl".equals(companyName)) { * * * sheetClone.addMergedRegion(new Region(attachStartRowClone + 2, * (short) 2, attachStartRowClone + 2, (short) 39)); * * sheetClone.addMergedRegion(new Region(attachStartRowClone + 2, * (short) 2, attachStartRowClone + 2, (short) 39)); * * * sheetClone.addMergedRegion(new CellRangeAddress( * attachStartRowClone + 2, attachStartRowClone + 2, 2, 39)); * * cellClone = rowClone.getCell(2); * * cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue(""); * * } * * cellClone = rowClone.getCell(40); * * cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue(""); * * cellClone = rowClone.getCell(44); * * cellClone.setCellStyle(styleCenter); * * cellClone.setCellValue(""); * * rowClone = sheetClone.getRow(attachStartRowClone + 4); * * cellClone = rowClone.getCell(0); * * // cellClone.setCellStyle(styleCenter); * * cellClone.setCellStyle(styleBorderThickLeftCenter); * * cellClone.setCellValue("1"); * * rowClone = sheetClone.getRow(attachStartRowClone + 4 + 1); * * cellClone = rowClone.getCell(0); * * cellClone.setCellStyle(styleBorderThickLeftCenter); * * * sheetClone.addMergedRegion(new Region(attachStartRowClone + 6, * (short) 0, 66, (short) 49)); * * sheetClone.addMergedRegion(new Region(attachStartRowClone + 6, * (short) 0, 66, (short) 49)); * * * sheetClone.addMergedRegion(new CellRangeAddress( * attachStartRowClone + 6, 66, 0, 49)); * * } * * } else { * * row = sheet.getRow(87); * * cell = row.getCell(34); * * cell.setCellValue(" 1 1 "); * * } * * if (fixSize > 0) { * * * sheet.addMergedRegion(new Region(21, (short) 0, 21, (short) 49)); * * sheet.addMergedRegion(new Region(21, (short) 0, 21, (short) 49)); * * * sheet.addMergedRegion(new CellRangeAddress(21, 21, 0, 49)); * * row = sheet.getRow(21); * * cell = row.getCell(0); * * // cell.setCellStyle(style); * * cell.setCellValue(""); * * cell.setCellStyle(styleBorderThickLeft); * * row = sheet.getRow(22); * * cell = row.getCell(0); * * cell.setCellStyle(styleBorderThickLeft); * * row = sheet.getRow(24); * * cell = row.getCell(0); * * cell.setCellStyle(styleBorderThickLeft); * * row = sheet.getRow(23); * * cell = row.getCell(0); * * // cell.setCellStyle(styleCenter); * * cell.setCellValue("??"); * * cell.setCellStyle(styleBorderThickLeftCenter); * * cell = row.getCell(2); * * cell.setCellStyle(styleCenter); * * cell.setCellValue("?"); * * cell = row.getCell(10); * * cell.setCellStyle(styleCenter); * * cell.setCellValue(""); * * cell = row.getCell(21); * * cell.setCellStyle(styleCenter); * * cell.setCellValue("?"); * * cell = row.getCell(24); * * cell.setCellStyle(styleCenter); * * cell.setCellValue(""); * * cell = row.getCell(30); * * cell.setCellStyle(styleCenter); * * cell.setCellValue(""); * * cell = row.getCell(34); * * cell.setCellStyle(styleCenter); * * cell.setCellValue("?"); * * cell = row.getCell(40); * * cell.setCellStyle(styleCenter); * * cell.setCellValue(""); * * cell = row.getCell(44); * * cell.setCellStyle(styleCenter); * * cell.setCellValue(""); * * for (int i = 0; i < maxFixSize; i++) { * * TbFixEntrustContent tbFixEntrustContent = * tbFixEntrustContentListAdd .get(i); * * row = sheet.getRow(25 + i * 2); * * cell = row.getCell(0); * * // cell.setCellStyle(styleCenter); * * cell.setCellValue(i + 1); * * cell = row.getCell(2); * * // cell.setCellStyle(styleCenter); * * cell.setCellValue(tbFixEntrustContent.getStationCode()); * * cell = row.getCell(10); * * // cell.setCellStyle(styleCenter); * * cell.setCellValue(tbFixEntrustContent.getStationName()); * * cell = row.getCell(21); * * // cell.setCellStyle(styleCenter); * * cell.setCellValue(tbFixEntrustContent.getZl()); * * cell = row.getCell(24); * * // cell.setCellStyle(styleCenter); * * cell.setCellValue(tbFixEntrustContent.getProjectType()); * * cell = row.getCell(30); * * // cell.setCellStyle(styleCenter); * * cell.setCellValue(new BigDecimal(tbFixEntrustContent * .getFixHour()).divide(new BigDecimal("1.00"), 2, * BigDecimal.ROUND_HALF_UP).toString()); * * cell = row.getCell(34); * * // cell.setCellStyle(styleCenter); * * cell.setCellValue(new BigDecimal(tbFixEntrustContent * .getWorkingHourPrice()) .divide(new BigDecimal("1.00"), 2, * BigDecimal.ROUND_HALF_UP).toString()); * * cell = row.getCell(40); * * // cell.setCellStyle(styleCenter); * * cell.setCellValue(new BigDecimal((1 - tbBusinessBalance * .getWorkingHourFavourRate()) * 100) .divide(new * BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); * * cell = row.getCell(44); * * // cell.setCellStyle(styleCenter); * * cell.setCellValue(new BigDecimal(tbFixEntrustContent * .getFixHourAll()).divide(new BigDecimal("1.00"), 2, * BigDecimal.ROUND_HALF_UP).toString()); } * * } * * if ((fixSize <= maxSize - 1) && partSize > 0) { * * * sheet.addMergedRegion(new Region(partStartRow, (short) 0, * partStartRow, (short) 49)); * * sheet.addMergedRegion(new Region(partStartRow, (short) 0, * partStartRow, (short) 49)); * * * sheet.addMergedRegion(new CellRangeAddress(partStartRow, * partStartRow, 0, 49)); * * row = sheet.getRow(partStartRow); * * cell = row.getCell(0); * * // cell.setCellStyle(style); * * cell.setCellValue(""); * * cell.setCellStyle(styleBorderThickLeft); * * row = sheet.getRow(partStartRow + 1); * * cell = row.getCell(0); * * cell.setCellStyle(styleBorderThickLeft); * * row = sheet.getRow(partStartRow + 2 + 1); * * cell = row.getCell(0); * * cell.setCellStyle(styleBorderThickLeftCenter); * * row = sheet.getRow(partStartRow + 2); * * cell = row.getCell(0); * * cell.setCellStyle(styleBorderThickLeftCenter); * * cell.setCellValue("??"); * * cell = row.getCell(2); * * cell.setCellStyle(styleCenter); * * cell.setCellValue("?"); * * cell = row.getCell(10); * * cell.setCellStyle(styleCenter); * * cell.setCellValue("??"); * * cell = row.getCell(21); * * cell.setCellStyle(styleCenter); * * cell.setCellValue("?"); * * cell = row.getCell(24); * * cell.setCellStyle(styleCenter); * * cell.setCellValue(""); * * cell = row.getCell(30); * * cell.setCellStyle(styleCenter); * * cell.setCellValue("?"); * * cell = row.getCell(34); * * cell.setCellStyle(styleCenter); * * cell.setCellValue("?"); * * cell = row.getCell(40); * * cell.setCellStyle(styleCenter); * * cell.setCellValue(""); * * cell = row.getCell(44); * * cell.setCellStyle(styleCenter); * * cell.setCellValue(""); * * if (partSize > 0) { * * for (int i = 0; i < maxPartSize; i++) { * * TbMaintianVo tbMaintianVo = maintianvosAdd.get(i); * * row = sheet.getRow(partStartRow + 4 + i * 2); * * cell = row.getCell(0); * * // cell.setCellStyle(styleCenter); * * cell.setCellValue(i + 1); * * cell = row.getCell(2); * * // cell.setCellStyle(styleCenter); * * cell.setCellValue(tbMaintianVo.getPartCode()); * * cell = row.getCell(10); * * // cell.setCellStyle(styleCenter); * * cell.setCellValue(tbMaintianVo.getPartName()); * * cell = row.getCell(21); * * // cell.setCellStyle(styleCenter); * * cell.setCellValue(tbMaintianVo.getZl()); * * cell = row.getCell(24); * * // cell.setCellStyle(styleCenter); * * cell.setCellValue(tbMaintianVo.getProjectType()); * * cell = row.getCell(30); * * cell.setCellStyle(styleRight); * * cell.setCellValue(new BigDecimal(tbMaintianVo * .getPartQuantity()).divide( new BigDecimal("1.00"), 2, * BigDecimal.ROUND_HALF_UP).toString()); * * cell = row.getCell(34); * * // cell.setCellStyle(styleCenter); * * cell.setCellValue(new BigDecimal(tbMaintianVo * .getPrice()).divide(new BigDecimal("1.00"), 2, * BigDecimal.ROUND_HALF_UP).toString()); * * cell = row.getCell(40); * * // cell.setCellStyle(styleCenter); * * cell.setCellValue(new BigDecimal((1 - tbBusinessBalance * .getFixPartFavourRate()) * 100).divide( new BigDecimal("1.00"), * 2, BigDecimal.ROUND_HALF_UP).toString()); * * cell = row.getCell(44); * * // cell.setCellStyle(styleCenter); * * cell.setCellValue(new BigDecimal(tbMaintianVo .getPartQuantity()) * .multiply( new BigDecimal(tbMaintianVo.getPrice())) .divide(new * BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); } * * } * * } * * int attachStartRow = 21; * * if ((fixSize + partSize) <= 17) { * * if (fixSize != 0 && partSize == 0 && fixSize < 18) { * * attachStartRow = 19 + 2 + 2 + 2 + fixSize * 2; * * } * * if (partSize != 0 && fixSize == 0 && partSize < 18) { * * attachStartRow = 19 + 2 + 2 + 2 + partSize * 2; } * * if (fixSize != 0 && partSize != 0 && (fixSize + partSize < 18)) { * * attachStartRow = 19 + 2 + 2 + 2 + 2 + 2 + fixSize * 2 + partSize * * 2; * * } * * * sheet.addMergedRegion(new Region(attachStartRow, (short) 0, * attachStartRow, (short) 49)); * * sheet.addMergedRegion(new Region(attachStartRow, (short) 0, * attachStartRow, (short) 49)); * * * sheet.addMergedRegion(new CellRangeAddress(attachStartRow, * attachStartRow, 0, 49)); * * row = sheet.getRow(attachStartRow); * * cell = row.getCell(0); * * // cell.setCellStyle(style); * * cell.setCellStyle(styleBorderThickLeft); * * cell.setCellValue(""); * * row = sheet.getRow(attachStartRow + 1); * * cell = row.getCell(0); * * cell.setCellStyle(styleBorderThickLeft); * * row = sheet.getRow(attachStartRow + 2 + 1); * * cell = row.getCell(0); * * cell.setCellStyle(styleBorderThickLeftCenter); * * row = sheet.getRow(attachStartRow + 2); * * cell = row.getCell(0); * * // cell.setCellStyle(styleCenter); * cell.setCellStyle(styleBorderThickLeftCenter); * * cell.setCellValue("??"); * * if ("dfbz".equals(companyName)) { * * cell = row.getCell(10); * * cell.setCellStyle(styleCenter); * * cell.setCellValue("??"); * * cell = row.getCell(21); * * cell.setCellStyle(styleCenter); * * cell.setCellValue("?"); * * cell = row.getCell(24); * * cell.setCellStyle(styleCenter); * * cell.setCellValue(""); * * cell = row.getCell(30); * * cell.setCellStyle(styleCenter); * * cell.setCellValue("?"); * * cell = row.getCell(34); * * cell.setCellStyle(styleCenter); * * cell.setCellValue("?"); * * cell = row.getCell(40); * * cell.setCellStyle(styleCenter); * * } else if ("xtl".equals(companyName)) { * * * sheet.addMergedRegion(new Region(attachStartRow + 2, (short) 2, * attachStartRow + 2, (short) 39)); * * sheet.addMergedRegion(new Region(attachStartRow + 2, (short) 2, * attachStartRow + 2, (short) 39)); * * * sheet.addMergedRegion(new CellRangeAddress( attachStartRow + 2, * attachStartRow + 2, 2, 39)); * * cell = row.getCell(2); * * cell.setCellStyle(styleCenter); * * cell.setCellValue(""); * * } * * * sheet.addMergedRegion(new Region(attachStartRow + 2, (short) 2, * attachStartRow + 2, (short) 39)); * * sheet.addMergedRegion(new Region(attachStartRow + 2, (short) 2, * attachStartRow + 2, (short) 39)); * * cell = row.getCell(2); * * cell.setCellStyle(styleCenter); * * cell.setCellValue(""); * * * cell = row.getCell(40); * * cell.setCellStyle(styleCenter); * * cell.setCellValue(""); * * cell = row.getCell(44); * * cell.setCellStyle(styleCenter); * * cell.setCellValue(""); * * row = sheet.getRow(attachStartRow + 4); * * cell = row.getCell(0); * * // cell.setCellStyle(styleCenter); * cell.setCellStyle(styleBorderThickLeftCenter); * * cell.setCellValue("1"); * * row = sheet.getRow(attachStartRow + 4 + 1); * * cell = row.getCell(0); * * cell.setCellStyle(styleBorderThickLeftCenter); * * if ("xtl".equals(companyName)) { * * * sheet.addMergedRegion(new Region(attachStartRow + 6, (short) 0, * 66, (short) 49)); * * sheet.addMergedRegion(new Region(attachStartRow + 6, (short) 0, * 66, (short) 49)); * * if (attachStartRow + 6 < 66) { * * sheet.addMergedRegion(new CellRangeAddress( attachStartRow + 6, * 66, 0, 49)); } * * } } */ int pageSize = 0; if ((fixSize > 0 && partSize == 0) || (partSize > 0 && fixSize == 0)) { if ((fixSize + partSize) <= 18) { pageSize = 1; } else { pageSize = (fixSize + partSize - 19) / 21 + 2; } for (int p = pageSize - 1; p >= 0; p--) { int maxSize = (p == pageSize - 1) ? (fixSize + partSize - p * 21) : 21; int startRow = 21; if (p == 0) { sheet = workbook.getSheetAt(0); for (int k = 1; k <= pageSize / 2; k++) { workbook.setSheetOrder(workbook.getSheetName(k), pageSize - k); } for (int k = 1; k < pageSize; k++) { workbook.setSheetName(k, "" + (k + 1) + ""); } workbook.setSheetName(0, "" + 1 + ""); } else { sheet = workbook.cloneSheet(0); //this.clearSheet(sheet, 21, 0, 66, 49); } if (fixSize > 0) { sheet.addMergedRegion(new CellRangeAddress(21, 21, 0, 49)); row = sheet.getRow(21); cell = row.getCell(0); cell.setCellValue(""); cell.setCellStyle(styleBorderThickLeft); row = sheet.getRow(22); cell = row.getCell(0); cell.setCellStyle(styleBorderThickLeft); row = sheet.getRow(24); cell = row.getCell(0); cell.setCellStyle(styleBorderThickLeft); row = sheet.getRow(23); cell = row.getCell(0); cell.setCellValue("??"); cell.setCellStyle(styleBorderThickLeftCenter); cell = row.getCell(2); cell.setCellStyle(styleCenter); cell.setCellValue("?"); cell = row.getCell(10); cell.setCellStyle(styleCenter); cell.setCellValue(""); cell = row.getCell(21); cell.setCellStyle(styleCenter); cell.setCellValue("?"); cell = row.getCell(24); cell.setCellStyle(styleCenter); cell.setCellValue(""); cell = row.getCell(30); cell.setCellStyle(styleCenter); cell.setCellValue(""); cell = row.getCell(34); cell.setCellStyle(styleCenter); cell.setCellValue("?"); cell = row.getCell(40); cell.setCellStyle(styleCenter); cell.setCellValue(""); cell = row.getCell(44); cell.setCellStyle(styleCenter); cell.setCellValue(""); for (int i = 0; i < maxSize; i++) { TbFixEntrustContent tbFixEntrustContent = tbFixEntrustContentListAdd.get(p * 21 + i); row = sheet.getRow(25 + i * 2); cell = row.getCell(0); // cell.setCellStyle(styleCenter); cell.setCellValue(p * 21 + i + 1); cell = row.getCell(2); // cell.setCellStyle(styleCenter); cell.setCellValue(tbFixEntrustContent.getStationCode()); cell = row.getCell(10); // cell.setCellStyle(styleCenter); cell.setCellValue(tbFixEntrustContent.getStationName()); cell = row.getCell(21); // cell.setCellStyle(styleCenter); cell.setCellValue(tbFixEntrustContent.getZl()); cell = row.getCell(24); // cell.setCellStyle(styleCenter); cell.setCellValue(tbFixEntrustContent.getProjectType()); cell = row.getCell(30); // cell.setCellStyle(styleCenter); cell.setCellValue(new BigDecimal(tbFixEntrustContent.getFixHour()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(34); // cell.setCellStyle(styleCenter); cell.setCellValue(new BigDecimal(tbFixEntrustContent.getWorkingHourPrice()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(40); // cell.setCellStyle(styleCenter); cell.setCellValue( new BigDecimal((1 - tbBusinessBalance.getWorkingHourFavourRate()) * 100) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP) .toString()); cell = row.getCell(44); // cell.setCellStyle(styleCenter); cell.setCellValue(new BigDecimal(tbFixEntrustContent.getFixHourAll()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); } } else if (partSize > 0) { sheet.addMergedRegion(new CellRangeAddress(startRow, startRow, 0, 49)); row = sheet.getRow(startRow); cell = row.getCell(0); // cell.setCellStyle(style); cell.setCellValue(""); cell.setCellStyle(styleBorderThickLeft); row = sheet.getRow(startRow + 1); cell = row.getCell(0); cell.setCellStyle(styleBorderThickLeft); row = sheet.getRow(startRow + 2 + 1); cell = row.getCell(0); cell.setCellStyle(styleBorderThickLeftCenter); row = sheet.getRow(startRow + 2); cell = row.getCell(0); cell.setCellStyle(styleBorderThickLeftCenter); cell.setCellValue("??"); cell = row.getCell(2); cell.setCellStyle(styleCenter); cell.setCellValue("?"); cell = row.getCell(10); cell.setCellStyle(styleCenter); cell.setCellValue("??"); cell = row.getCell(21); cell.setCellStyle(styleCenter); cell.setCellValue("?"); cell = row.getCell(24); cell.setCellStyle(styleCenter); cell.setCellValue(""); cell = row.getCell(30); cell.setCellStyle(styleCenter); cell.setCellValue("?"); cell = row.getCell(34); cell.setCellStyle(styleCenter); cell.setCellValue("?"); cell = row.getCell(40); cell.setCellStyle(styleCenter); cell.setCellValue(""); cell = row.getCell(44); cell.setCellStyle(styleCenter); cell.setCellValue(""); for (int i = 0; i < maxSize; i++) { TbMaintianVo tbMaintianVo = maintianvosAdd.get(p * 21 + i); row = sheet.getRow(startRow + 4 + i * 2); cell = row.getCell(0); // cell.setCellStyle(styleCenter); cell.setCellValue(p * 21 + i + 1); cell = row.getCell(2); // cell.setCellStyle(styleCenter); cell.setCellValue(tbMaintianVo.getPartCode()); cell = row.getCell(10); // cell.setCellStyle(styleCenter); cell.setCellValue(tbMaintianVo.getPartName()); cell = row.getCell(21); // cell.setCellStyle(styleCenter); cell.setCellValue(tbMaintianVo.getZl()); cell = row.getCell(24); // cell.setCellStyle(styleCenter); cell.setCellValue(tbMaintianVo.getProjectType()); cell = row.getCell(30); cell.setCellStyle(styleRight); cell.setCellValue(new BigDecimal(tbMaintianVo.getPartQuantity()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(34); // cell.setCellStyle(styleCenter); cell.setCellValue(new BigDecimal(tbMaintianVo.getPrice()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(40); // cell.setCellStyle(styleCenter); cell.setCellValue(new BigDecimal((1 - tbBusinessBalance.getFixPartFavourRate()) * 100) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(44); // cell.setCellStyle(styleCenter); cell.setCellValue(new BigDecimal(tbMaintianVo.getPartQuantity()) .multiply(new BigDecimal(tbMaintianVo.getPrice())) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); } } row = sheet.getRow(87); cell = row.getCell(34); cell.setCellValue(" " + (p + 1) + " " + pageSize + " "); if (p == pageSize - 1) { int attachStartRow = 21 + 2 + 2 + (fixSize + partSize - (pageSize - 1) * 21) * 2; sheet.addMergedRegion(new CellRangeAddress(attachStartRow, attachStartRow, 0, 49)); row = sheet.getRow(attachStartRow); cell = row.getCell(0); cell.setCellStyle(styleBorderThickLeft); cell.setCellValue(""); row = sheet.getRow(attachStartRow + 1); cell = row.getCell(0); cell.setCellStyle(styleBorderThickLeft); row = sheet.getRow(attachStartRow + 2 + 1); cell = row.getCell(0); cell.setCellStyle(styleBorderThickLeftCenter); row = sheet.getRow(attachStartRow + 2); cell = row.getCell(0); // cell.setCellStyle(styleCenter); cell.setCellStyle(styleBorderThickLeftCenter); cell.setCellValue("??"); if ("dfbz".equals(companyName)) { cell = row.getCell(10); cell.setCellStyle(styleCenter); cell.setCellValue("??"); cell = row.getCell(21); cell.setCellStyle(styleCenter); cell.setCellValue("?"); cell = row.getCell(24); cell.setCellStyle(styleCenter); cell.setCellValue(""); cell = row.getCell(30); cell.setCellStyle(styleCenter); cell.setCellValue("?"); cell = row.getCell(34); cell.setCellStyle(styleCenter); cell.setCellValue("?"); cell = row.getCell(40); cell.setCellStyle(styleCenter); } else if ("xtl".equals(companyName)) { cell = row.getCell(2); cell.setCellStyle(styleCenter); cell.setCellValue(""); } cell = row.getCell(40); cell.setCellStyle(styleCenter); cell.setCellValue(""); cell = row.getCell(44); cell.setCellStyle(styleCenter); cell.setCellValue(""); row = sheet.getRow(attachStartRow + 4); cell = row.getCell(0); // cell.setCellStyle(styleCenter); cell.setCellStyle(styleBorderThickLeftCenter); cell.setCellValue("1"); row = sheet.getRow(attachStartRow + 4 + 1); cell = row.getCell(0); cell.setCellStyle(styleBorderThickLeftCenter); if ("xtl".equals(companyName)) { if (attachStartRow + 6 < 66) { sheet.addMergedRegion(new CellRangeAddress(attachStartRow + 6, 66, 0, 49)); } } } } } if (fixSize > 0 && partSize > 0) { if ((fixSize + partSize) <= 16) { pageSize = 1; } else { pageSize = (fixSize + partSize - 17) / 19 + 2; } int fixPageSize = fixSize / pageSize; int partPageSize = partSize / pageSize; int fixLastPageSize = fixSize - (pageSize - 1) * fixPageSize; int partLastPageSize = partSize - (pageSize - 1) * partPageSize; if ((fixPageSize + partPageSize) < 19 && fixPageSize != 0) { //if(fixLastPageSize >= partSize){ if (fixPageSize >= partPageSize) { fixPageSize = (19 - partPageSize) > fixSize ? fixSize : (19 - partPageSize); } else { partPageSize = (19 - fixPageSize) > partSize ? partSize : (19 - fixPageSize); } } fixLastPageSize = fixSize - (pageSize - 1) * fixPageSize; partLastPageSize = (partSize - (pageSize - 1) * partPageSize) < 0 ? 0 : (partSize - (pageSize - 1) * partPageSize); for (int p = pageSize - 1; p >= 0; p--) { int partStartRow = 21 + 2 + 2 + ((p == pageSize - 1) ? fixLastPageSize : fixPageSize) * 2; if (p == 0) { sheet = workbook.getSheetAt(0); if (pageSize > 1) { for (int k = 1; k <= pageSize / 2; k++) { workbook.setSheetOrder(workbook.getSheetName(k), pageSize - k); } for (int k = 1; k < pageSize; k++) { workbook.setSheetName(k, "" + (k + 1) + ""); } } workbook.setSheetName(0, "" + 1 + ""); } else { sheet = workbook.cloneSheet(0); } if (fixSize > 0) { sheet.addMergedRegion(new CellRangeAddress(21, 21, 0, 49)); row = sheet.getRow(21); cell = row.getCell(0); cell.setCellValue(""); cell.setCellStyle(styleBorderThickLeft); row = sheet.getRow(22); cell = row.getCell(0); cell.setCellStyle(styleBorderThickLeft); row = sheet.getRow(24); cell = row.getCell(0); cell.setCellStyle(styleBorderThickLeft); row = sheet.getRow(23); cell = row.getCell(0); cell.setCellValue("??"); cell.setCellStyle(styleBorderThickLeftCenter); cell = row.getCell(2); cell.setCellStyle(styleCenter); cell.setCellValue("?"); cell = row.getCell(10); cell.setCellStyle(styleCenter); cell.setCellValue(""); cell = row.getCell(21); cell.setCellStyle(styleCenter); cell.setCellValue("?"); cell = row.getCell(24); cell.setCellStyle(styleCenter); cell.setCellValue(""); cell = row.getCell(30); cell.setCellStyle(styleCenter); cell.setCellValue(""); cell = row.getCell(34); cell.setCellStyle(styleCenter); cell.setCellValue("?"); cell = row.getCell(40); cell.setCellStyle(styleCenter); cell.setCellValue(""); cell = row.getCell(44); cell.setCellStyle(styleCenter); cell.setCellValue(""); for (int i = 0; i < ((p == pageSize - 1) ? fixLastPageSize : fixPageSize); i++) { TbFixEntrustContent tbFixEntrustContent = tbFixEntrustContentListAdd .get(p * fixPageSize + i); row = sheet.getRow(25 + i * 2); cell = row.getCell(0); // cell.setCellStyle(styleCenter); cell.setCellValue(p * fixPageSize + i + 1); cell = row.getCell(2); // cell.setCellStyle(styleCenter); cell.setCellValue(tbFixEntrustContent.getStationCode()); cell = row.getCell(10); // cell.setCellStyle(styleCenter); cell.setCellValue(tbFixEntrustContent.getStationName()); cell = row.getCell(21); // cell.setCellStyle(styleCenter); cell.setCellValue(tbFixEntrustContent.getZl()); cell = row.getCell(24); // cell.setCellStyle(styleCenter); cell.setCellValue(tbFixEntrustContent.getProjectType()); cell = row.getCell(30); // cell.setCellStyle(styleCenter); cell.setCellValue(new BigDecimal(tbFixEntrustContent.getFixHour()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(34); // cell.setCellStyle(styleCenter); cell.setCellValue(new BigDecimal(tbFixEntrustContent.getWorkingHourPrice()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(40); // cell.setCellStyle(styleCenter); cell.setCellValue( new BigDecimal((1 - tbBusinessBalance.getWorkingHourFavourRate()) * 100) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP) .toString()); cell = row.getCell(44); // cell.setCellStyle(styleCenter); cell.setCellValue(new BigDecimal(tbFixEntrustContent.getFixHourAll()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); } } if (partSize > 0) { sheet.addMergedRegion(new CellRangeAddress(partStartRow, partStartRow, 0, 49)); row = sheet.getRow(partStartRow); cell = row.getCell(0); // cell.setCellStyle(style); cell.setCellValue(""); cell.setCellStyle(styleBorderThickLeft); row = sheet.getRow(partStartRow + 1); cell = row.getCell(0); cell.setCellStyle(styleBorderThickLeft); row = sheet.getRow(partStartRow + 2 + 1); cell = row.getCell(0); cell.setCellStyle(styleBorderThickLeftCenter); row = sheet.getRow(partStartRow + 2); cell = row.getCell(0); cell.setCellStyle(styleBorderThickLeftCenter); cell.setCellValue("??"); cell = row.getCell(2); cell.setCellStyle(styleCenter); cell.setCellValue("?"); cell = row.getCell(10); cell.setCellStyle(styleCenter); cell.setCellValue("??"); cell = row.getCell(21); cell.setCellStyle(styleCenter); cell.setCellValue("?"); cell = row.getCell(24); cell.setCellStyle(styleCenter); cell.setCellValue(""); cell = row.getCell(30); cell.setCellStyle(styleCenter); cell.setCellValue("?"); cell = row.getCell(34); cell.setCellStyle(styleCenter); cell.setCellValue("?"); cell = row.getCell(40); cell.setCellStyle(styleCenter); cell.setCellValue(""); cell = row.getCell(44); cell.setCellStyle(styleCenter); cell.setCellValue(""); for (int i = 0; i < ((p == pageSize - 1) ? partLastPageSize : partPageSize); i++) { if (p * partPageSize + i > partSize - 1) { break; } TbMaintianVo tbMaintianVo = maintianvosAdd.get(p * partPageSize + i); row = sheet.getRow(partStartRow + 4 + i * 2); cell = row.getCell(0); // cell.setCellStyle(styleCenter); cell.setCellValue(p * partPageSize + i + 1); cell = row.getCell(2); // cell.setCellStyle(styleCenter); cell.setCellValue(tbMaintianVo.getPartCode()); cell = row.getCell(10); // cell.setCellStyle(styleCenter); cell.setCellValue(tbMaintianVo.getPartName()); cell = row.getCell(21); // cell.setCellStyle(styleCenter); cell.setCellValue(tbMaintianVo.getZl()); cell = row.getCell(24); // cell.setCellStyle(styleCenter); cell.setCellValue(tbMaintianVo.getProjectType()); cell = row.getCell(30); cell.setCellStyle(styleRight); cell.setCellValue(new BigDecimal(tbMaintianVo.getPartQuantity()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(34); // cell.setCellStyle(styleCenter); cell.setCellValue(new BigDecimal(tbMaintianVo.getPrice()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(40); // cell.setCellStyle(styleCenter); cell.setCellValue(new BigDecimal((1 - tbBusinessBalance.getFixPartFavourRate()) * 100) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(44); // cell.setCellStyle(styleCenter); cell.setCellValue(new BigDecimal(tbMaintianVo.getPartQuantity()) .multiply(new BigDecimal(tbMaintianVo.getPrice())) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); } } row = sheet.getRow(87); cell = row.getCell(34); cell.setCellValue(" " + (p + 1) + " " + pageSize + " "); if (p == pageSize - 1) { int attachStartRow = 21 + 2 + 2 + 2 + 2 + (fixLastPageSize + partLastPageSize) * 2; sheet.addMergedRegion(new CellRangeAddress(attachStartRow, attachStartRow, 0, 49)); row = sheet.getRow(attachStartRow); cell = row.getCell(0); cell.setCellStyle(styleBorderThickLeft); cell.setCellValue(""); row = sheet.getRow(attachStartRow + 1); cell = row.getCell(0); cell.setCellStyle(styleBorderThickLeft); row = sheet.getRow(attachStartRow + 2 + 1); cell = row.getCell(0); cell.setCellStyle(styleBorderThickLeftCenter); row = sheet.getRow(attachStartRow + 2); cell = row.getCell(0); // cell.setCellStyle(styleCenter); cell.setCellStyle(styleBorderThickLeftCenter); cell.setCellValue("??"); if ("dfbz".equals(companyName)) { cell = row.getCell(10); cell.setCellStyle(styleCenter); cell.setCellValue("??"); cell = row.getCell(21); cell.setCellStyle(styleCenter); cell.setCellValue("?"); cell = row.getCell(24); cell.setCellStyle(styleCenter); cell.setCellValue(""); cell = row.getCell(30); cell.setCellStyle(styleCenter); cell.setCellValue("?"); cell = row.getCell(34); cell.setCellStyle(styleCenter); cell.setCellValue("?"); cell = row.getCell(40); cell.setCellStyle(styleCenter); } else if ("xtl".equals(companyName)) { cell = row.getCell(2); cell.setCellStyle(styleCenter); cell.setCellValue(""); } cell = row.getCell(40); cell.setCellStyle(styleCenter); cell.setCellValue(""); cell = row.getCell(44); cell.setCellStyle(styleCenter); cell.setCellValue(""); row = sheet.getRow(attachStartRow + 4); cell = row.getCell(0); // cell.setCellStyle(styleCenter); cell.setCellStyle(styleBorderThickLeftCenter); cell.setCellValue("1"); row = sheet.getRow(attachStartRow + 4 + 1); cell = row.getCell(0); cell.setCellStyle(styleBorderThickLeftCenter); if ("xtl".equals(companyName)) { if (attachStartRow + 6 < 66) { sheet.addMergedRegion(new CellRangeAddress(attachStartRow + 6, 66, 0, 49)); } } } } } workbook.write(os); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // 8 41 }
From source file:com.taobao.itest.dbunit.dataset.excel.XlsDataSetWriter.java
License:Open Source License
/** * Write the specified dataset to the specified Excel document. *//* www . j a v a 2 s .c o m*/ public void write(IDataSet dataSet, OutputStream out) throws IOException, DataSetException { logger.debug("write(dataSet={}, out={}) - start", dataSet, out); HSSFWorkbook workbook = new HSSFWorkbook(); this.dateCellStyle = createDateCellStyle(workbook); int index = 0; ITableIterator iterator = dataSet.iterator(); while (iterator.next()) { // create the table i.e. sheet ITable table = iterator.getTable(); ITableMetaData metaData = table.getTableMetaData(); HSSFSheet sheet = workbook.createSheet(metaData.getTableName()); // write table metadata i.e. first row in sheet workbook.setSheetName(index, metaData.getTableName()); HSSFRow headerRow = sheet.createRow(0); Column[] columns = metaData.getColumns(); for (int j = 0; j < columns.length; j++) { Column column = columns[j]; HSSFCell cell = headerRow.createCell(j); cell.setCellValue(new HSSFRichTextString(column.getColumnName())); } // write table data for (int j = 0; j < table.getRowCount(); j++) { HSSFRow row = sheet.createRow(j + 1); for (int k = 0; k < columns.length; k++) { Column column = columns[k]; Object value = table.getValue(j, column.getColumnName()); if (value != null) { HSSFCell cell = row.createCell(k); if (value instanceof Date) { setDateCell(cell, (Date) value, workbook); } else if (value instanceof BigDecimal) { setNumericCell(cell, (BigDecimal) value, workbook); } else if (value instanceof Long) { setDateCell(cell, new Date(((Long) value).longValue()), workbook); } else { cell.setCellValue(new HSSFRichTextString(DataType.asString(value))); } } } } index++; } // write xls document workbook.write(out); out.flush(); }
From source file:com.webbfontaine.valuewebb.report.fcvrprocessing.FcvrTimeReportEngine.java
License:Open Source License
public static final ReportProcessResult processReport(String query, FcvrProcessingTimeReportBean reportBean) { try (Connection connection = Utils.getSQLConnection(); PreparedStatement preparedStatement = setPreparedStatementParams(connection.prepareStatement(query), reportBean);// w ww . j a va 2 s . c om ResultSet resultSet = preparedStatement.executeQuery(); InputStream is = getTemplateFileStream()) { resultSet.setFetchSize(1000); HSSFWorkbook workbook = new HSSFWorkbook(is); workbook.setSheetName(0, "Time Processing"); workbook.setSheetName(1, "Containers"); int generatedRows = createRows(workbook, resultSet); if (generatedRows == DEFAULT_STARTING_ROW_NUMBER) { return ReportProcessResult.REPORT_IS_EMPTY; } exportWorkBook(workbook); return ReportProcessResult.PROCESSING_SUCCEED; } catch (SQLException | IOException e) { LOGGER.error("Error occurred during FcvrTimeReport", e); return ReportProcessResult.PROCESSING_FAILED; } }
From source file:demo.poi.BigExample.java
License:Apache License
public static void main(String[] args) throws IOException { int rownum;/*from ww w .j a v a 2 s. com*/ // create a new file FileOutputStream out = new FileOutputStream("target/bigworkbook.xls"); // create a new workbook HSSFWorkbook wb = new HSSFWorkbook(); // create a new sheet HSSFSheet s = wb.createSheet(); // declare a row object reference HSSFRow r = null; // declare a cell object reference HSSFCell c = null; // create 3 cell styles HSSFCellStyle cs = wb.createCellStyle(); HSSFCellStyle cs2 = wb.createCellStyle(); HSSFCellStyle cs3 = wb.createCellStyle(); // create 2 fonts objects HSSFFont f = wb.createFont(); HSSFFont f2 = wb.createFont(); //set font 1 to 12 point type f.setFontHeightInPoints((short) 12); //make it red f.setColor(HSSFColor.RED.index); // make it bold //arial is the default font f.setBoldweight(Font.BOLDWEIGHT_BOLD); //set font 2 to 10 point type f2.setFontHeightInPoints((short) 10); //make it the color at palette index 0xf (white) f2.setColor(HSSFColor.WHITE.index); //make it bold f2.setBoldweight(Font.BOLDWEIGHT_BOLD); //set cell stlye cs.setFont(f); //set the cell format see HSSFDataFromat for a full list cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("($#,##0_);[Red]($#,##0)")); //set a thin border cs2.setBorderBottom(CellStyle.BORDER_THIN); //fill w fg fill color cs2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // set foreground fill to red cs2.setFillForegroundColor(HSSFColor.RED.index); // set the font cs2.setFont(f2); // set the sheet name to HSSF Test wb.setSheetName(0, "HSSF Test"); // create a sheet with 300 rows (0-299) for (rownum = 0; rownum < 300; rownum++) { // create a row r = s.createRow(rownum); // on every other row if ((rownum % 2) == 0) { // make the row height bigger (in twips - 1/20 of a point) r.setHeight((short) 0x249); } //r.setRowNum(( short ) rownum); // create 50 cells (0-49) (the += 2 becomes apparent later for (int cellnum = 0; cellnum < 50; cellnum += 2) { // create a numeric cell c = r.createCell(cellnum); // do some goofy math to demonstrate decimals c.setCellValue(rownum * 10000 + cellnum + (((double) rownum / 1000) + ((double) cellnum / 10000))); // on every other row if ((rownum % 2) == 0) { // set this cell to the first cell style we defined c.setCellStyle(cs); } // create a string cell (see why += 2 in the c = r.createCell(cellnum + 1); // set the cell's string value to "TEST" c.setCellValue("TEST"); // make this column a bit wider s.setColumnWidth(cellnum + 1, (int) ((50 * 8) / ((double) 1 / 20))); // on every other row if ((rownum % 2) == 0) { // set this to the white on red cell style // we defined above c.setCellStyle(cs2); } } } //draw a thick black border on the row at the bottom using BLANKS // advance 2 rows rownum++; rownum++; r = s.createRow(rownum); // define the third style to be the default // except with a thick black border at the bottom cs3.setBorderBottom(CellStyle.BORDER_THICK); //create 50 cells for (int cellnum = 0; cellnum < 50; cellnum++) { //create a blank type cell (no value) c = r.createCell(cellnum); // set it to the thick black border style c.setCellStyle(cs3); } //end draw thick black border // demonstrate adding/naming and deleting a sheet // create a sheet, set its title then delete it s = wb.createSheet(); wb.setSheetName(1, "DeletedSheet"); wb.removeSheetAt(1); //end deleted sheet // write the workbook to the output stream // close our file (don't blow out our file handles wb.write(out); out.close(); }
From source file:edu.jhu.cvrg.services.nodeDataService.DataStaging.java
License:Open Source License
/** Service to make final destination directories and transfer the file into it, via routeToFolder().<BR/> * Assumes that the file was already transfered to the ftp area. * // w w w . j a v a2 s . com * @param param0 OMElement containing the parameters:<BR/> * userId, subjectId, fileName, ftpHost, ftpUser, ftpPassword, bExposure * @return ??? always returns SUCCESS ??? * @throws Exception */ @SuppressWarnings("deprecation") public org.apache.axiom.om.OMElement consolidateCsvs(org.apache.axiom.om.OMElement param0) throws Exception { System.out.println("# consolidateCsvs() #"); OMFactory fac = OMAbstractFactory.getOMFactory(); OMNamespace omNs = fac.createOMNamespace("http://www.cvrgrid.org/nodeDataService/", "nodeDataService"); OMElement stageTransferredDataStatus = fac.createOMElement("stageTransferredData", omNs); Iterator iterator = param0.getChildren(); String userId = ((OMElement) iterator.next()).getText(); String chesSubjectIds = ((OMElement) iterator.next()).getText(); String bergSubjectIds = ((OMElement) iterator.next()).getText(); String chesFileNames = ((OMElement) iterator.next()).getText(); String bergFileNames = ((OMElement) iterator.next()).getText(); Boolean isPublic = new Boolean(((OMElement) iterator.next()).getText()).booleanValue(); String ftpHost = ((OMElement) iterator.next()).getText(); String ftpUser = ((OMElement) iterator.next()).getText(); String ftpPassword = ((OMElement) iterator.next()).getText(); String service = ((OMElement) iterator.next()).getText(); long logindatetime = new Long(((OMElement) iterator.next()).getText()).longValue(); String qrsScoreSubjectIds = ((OMElement) iterator.next()).getText(); String qrsScoreFileNames = ((OMElement) iterator.next()).getText(); try { verbose = new Boolean(((OMElement) iterator.next()).getText()).booleanValue(); } catch (NoSuchElementException nseEx) { System.out.println( "'iteration has no more elements' Exception while parsing 'verbose' in consolidateCsvs()"); } String publicOrPrivate = null; if (isPublic) { publicOrPrivate = "public"; } else { publicOrPrivate = "private"; } debugPrintln("userId: \"" + userId + "\""); debugPrintln("chesSubjectIds: \"" + chesSubjectIds + "\""); debugPrintln("bergSubjectIds: \"" + bergSubjectIds + "\""); debugPrintln("chesFileNames: \"" + chesFileNames + "\""); debugPrintln("bergFileNames: \"" + bergFileNames + "\""); debugPrintln("isPublic: \"" + isPublic + "\""); debugPrintln("ftpHost: \"" + ftpHost + "\""); debugPrintln("ftpUser: \"" + ftpUser + "\""); debugPrintln("ftpPassword: \"" + ftpPassword + "\""); debugPrintln("service: \"" + service + "\""); debugPrintln("logindatetime: \"" + logindatetime + "\""); debugPrintln("qrsScoreSubjectIds: \"" + qrsScoreSubjectIds + "\""); debugPrintln("qrsScoreFileNames: \"" + qrsScoreFileNames + "\""); debugPrintln("verbose: \"" + verbose + "\""); String timestamp = utils.generateTimeStamp(); String allResultsFileName = "allResultsFiles_" + userId + "_" + timestamp + ".xls"; String localAllResultsDirectory = findRelativePath("./", localWebPageRoot + sep + downloadDirectory); // put files to be allResults spreadsheet in here. String urlAllResultsDirectory = urlWebPageRoot + downloadDirectory; // URL as seen from the internet that is equivalent to localOutputDirectory above. e.g. http://icmv058.icm.jhu.edu:8080/download try { ApacheCommonsFtpWrapper ftpClient = new ApacheCommonsFtpWrapper(ftpHost, ftpUser, ftpPassword); ftpClient.verbose = verbose; System.out.println(userId + " Ches File Names: " + chesFileNames + "Berg File Names " + bergFileNames); System.out.println(userId + " Ches Subjects: " + chesSubjectIds + "Berg Subjects " + bergSubjectIds); FileOutputStream out = new FileOutputStream(localAllResultsDirectory + sep + allResultsFileName); HSSFWorkbook wbo = new HSSFWorkbook(); int numSheets = 0; if (!chesSubjectIds.equals("")) { HSSFSheet chesSheet = wbo.createSheet(); chesSheet = consolidateAlgorithmFiles(0, chesSheet, chesSubjectIds, userId, chesFileNames, isPublic, ftpClient); wbo.setSheetName(numSheets, "Chesnokov Results"); ++numSheets; } if (!bergSubjectIds.equals("")) { HSSFSheet bergerSheet = wbo.createSheet(); bergerSheet = consolidateAlgorithmFiles(1, bergerSheet, bergSubjectIds, userId, bergFileNames, isPublic, ftpClient); wbo.setSheetName(numSheets, "Berger Results"); ++numSheets; } if (!qrsScoreSubjectIds.equals("")) { HSSFSheet qrsScoreSheet = wbo.createSheet(); qrsScoreSheet = consolidateAlgorithmFiles(1, qrsScoreSheet, qrsScoreSubjectIds, userId, qrsScoreFileNames, isPublic, ftpClient); wbo.setSheetName(numSheets, "QRS-Score Results"); ++numSheets; } wbo.write(out); out.close(); } catch (IOException e) { e.printStackTrace(); } debugPrintln(bergSubjectIds); debugPrintln(chesSubjectIds); debugPrintln(qrsScoreSubjectIds); stageTransferredDataStatus.addChild(fac.createOMText(urlAllResultsDirectory + sep + allResultsFileName)); debugPrintln("Returning results URL: \"" + urlAllResultsDirectory + sep + allResultsFileName + "\""); return stageTransferredDataStatus; }
From source file:edu.jhu.cvrg.services.nodeDataService.DataStaging.java
License:Open Source License
/** Service to make final destination directories and transfer the file into it, via routeToFolder().<BR/> * Assumes that the file was already transfered to the ftp area. * //from w ww .j a v a2 s . c om * @param param0 OMElement containing the parameters:<BR/> * userId, subjectId, fileName, ftpHost, ftpUser, ftpPassword, bExposure * @return ??? always returns SUCCESS ??? * @throws Exception */ @SuppressWarnings("deprecation") public org.apache.axiom.om.OMElement consolidateCsvsForWaveform(org.apache.axiom.om.OMElement param0) throws Exception { System.out.println("# consolidateCsvsForWaveform() #"); OMFactory fac = OMAbstractFactory.getOMFactory(); OMNamespace omNs = fac.createOMNamespace("http://www.cvrgrid.org/nodeDataService/", "nodeDataService"); OMElement stageTransferredDataStatus = fac.createOMElement("stageTransferredData", omNs); Iterator iterator = param0.getChildren(); String userId = ((OMElement) iterator.next()).getText(); String chesSubjectIds = ((OMElement) iterator.next()).getText(); String bergSubjectIds = ((OMElement) iterator.next()).getText(); String chesFileNames = ((OMElement) iterator.next()).getText(); String bergFileNames = ((OMElement) iterator.next()).getText(); Boolean isPublic = new Boolean(((OMElement) iterator.next()).getText()).booleanValue(); String ftpHost = ((OMElement) iterator.next()).getText(); String ftpUser = ((OMElement) iterator.next()).getText(); String ftpPassword = ((OMElement) iterator.next()).getText(); String service = ((OMElement) iterator.next()).getText(); long logindatetime = new Long(((OMElement) iterator.next()).getText()).longValue(); String qrsScoreSubjectIds = ((OMElement) iterator.next()).getText(); String qrsScoreFileNames = ((OMElement) iterator.next()).getText(); try { verbose = new Boolean(((OMElement) iterator.next()).getText()).booleanValue(); } catch (NoSuchElementException nseEx) { System.out.println( "'iteration has no more elements' Exception while parsing 'verbose' in consolidateCsvs()"); } String publicOrPrivate = null; if (isPublic) { publicOrPrivate = "public"; } else { publicOrPrivate = "private"; } debugPrintln("userId: \"" + userId + "\""); debugPrintln("chesSubjectIds: \"" + chesSubjectIds + "\""); debugPrintln("bergSubjectIds: \"" + bergSubjectIds + "\""); debugPrintln("chesFileNames: \"" + chesFileNames + "\""); debugPrintln("bergFileNames: \"" + bergFileNames + "\""); debugPrintln("isPublic: \"" + isPublic + "\""); debugPrintln("ftpHost: \"" + ftpHost + "\""); debugPrintln("ftpUser: \"" + ftpUser + "\""); debugPrintln("ftpPassword: \"" + ftpPassword + "\""); debugPrintln("service: \"" + service + "\""); debugPrintln("logindatetime: \"" + logindatetime + "\""); debugPrintln("qrsScoreSubjectIds: \"" + qrsScoreSubjectIds + "\""); debugPrintln("qrsScoreFileNames: \"" + qrsScoreFileNames + "\""); debugPrintln("verbose: \"" + verbose + "\""); String timestamp = utils.generateTimeStamp(); String allResultsFileName = "allResultsFiles_" + userId + "_" + timestamp + ".xls"; String localAllResultsDirectory = localFtpRoot; // put files to be allResults spreadsheet in here. try { ApacheCommonsFtpWrapper ftpClient = new ApacheCommonsFtpWrapper(ftpHost, ftpUser, ftpPassword); ftpClient.verbose = verbose; System.out.println(userId + " Ches File Names: " + chesFileNames + "Berg File Names " + bergFileNames); System.out.println(userId + " Ches Subjects: " + chesSubjectIds + "Berg Subjects " + bergSubjectIds); FileOutputStream out = new FileOutputStream(localAllResultsDirectory + sep + allResultsFileName); HSSFWorkbook wbo = new HSSFWorkbook(); int numSheets = 0; if (!chesSubjectIds.equals("")) { HSSFSheet chesSheet = wbo.createSheet(); chesSheet = consolidateAlgorithmFiles(0, chesSheet, chesSubjectIds, userId, chesFileNames, isPublic, ftpClient); wbo.setSheetName(numSheets, "Chesnokov Results"); ++numSheets; } if (!bergSubjectIds.equals("")) { HSSFSheet bergerSheet = wbo.createSheet(); bergerSheet = consolidateAlgorithmFiles(1, bergerSheet, bergSubjectIds, userId, bergFileNames, isPublic, ftpClient); wbo.setSheetName(numSheets, "Berger Results"); ++numSheets; } if (!qrsScoreSubjectIds.equals("")) { HSSFSheet qrsScoreSheet = wbo.createSheet(); qrsScoreSheet = consolidateAlgorithmFiles(1, qrsScoreSheet, qrsScoreSubjectIds, userId, qrsScoreFileNames, isPublic, ftpClient); wbo.setSheetName(numSheets, "QRS-Score Results"); ++numSheets; } wbo.write(out); out.close(); } catch (IOException e) { e.printStackTrace(); } debugPrintln(bergSubjectIds); debugPrintln(chesSubjectIds); debugPrintln(qrsScoreSubjectIds); stageTransferredDataStatus.addChild(fac.createOMText(localAllResultsDirectory + sep + allResultsFileName)); debugPrintln("Returning results path: \"" + localAllResultsDirectory + sep + allResultsFileName + "\""); return stageTransferredDataStatus; }
From source file:edu.ku.brc.dbsupport.TableModel2Excel.java
License:Open Source License
/** * Converts a tableModel to an Excel Spreadsheet. * @param toFile the file object to write it to. * @param title the title of the spreadsheet. * @param tableModel the table model/*from w w w.j a v a2 s . c om*/ * @return a file to a spreadsheet */ public static File convertToExcel(final File toFile, final String title, final TableModel tableModel) { if (toFile == null) { UIRegistry.showLocalizedMsg("WARNING", "FILE_NO_EXISTS", toFile != null ? toFile.getAbsolutePath() : ""); return null; } if (tableModel != null && tableModel.getRowCount() > 0) { try { // create a new file FileOutputStream out; try { out = new FileOutputStream(toFile); } catch (FileNotFoundException ex) { UIRegistry.showLocalizedMsg("WARNING", "FILE_NO_WRITE", toFile != null ? toFile.getAbsolutePath() : ""); return null; } // create a new workbook HSSFWorkbook wb = new HSSFWorkbook(); // create a new sheet HSSFSheet sheet = wb.createSheet(); // declare a row object reference // Header Captions HSSFFont headerFont = wb.createFont(); headerFont.setFontHeightInPoints((short) 12); headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); // create a style for the header cell HSSFCellStyle headerStyle = wb.createCellStyle(); headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); headerStyle.setFont(headerFont); setBordersOnStyle(headerStyle, HSSFColor.GREY_25_PERCENT.index, HSSFCellStyle.BORDER_THIN); short numColumns = (short) tableModel.getColumnCount(); HSSFRow headerRow = sheet.createRow(0); for (int i = 0; i < numColumns; i++) { HSSFCell headerCell = headerRow.createCell((short) i); headerCell.setCellStyle(headerStyle); //add the date to the header cell headerCell.setCellValue(tableModel.getColumnName(i)); sheet.setColumnWidth((short) i, (short) (30 * 256)); } //-------------------------- // done header //-------------------------- // create 3 cell styles HSSFCellStyle oddCellStyle = wb.createCellStyle(); HSSFCellStyle evenCellStyle = wb.createCellStyle(); setBordersOnStyle(oddCellStyle, HSSFColor.GREY_25_PERCENT.index, HSSFCellStyle.BORDER_THIN); setBordersOnStyle(evenCellStyle, HSSFColor.GREY_25_PERCENT.index, HSSFCellStyle.BORDER_THIN); // create 2 fonts objects HSSFFont cellFont = wb.createFont(); //set font 1 to 12 point type cellFont.setFontHeightInPoints((short) 11); oddCellStyle.setFont(cellFont); evenCellStyle.setFont(cellFont); evenCellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); oddCellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); oddCellStyle.setFillForegroundColor(HSSFColor.WHITE.index); evenCellStyle.setFillForegroundColor(HSSFColor.LIGHT_CORNFLOWER_BLUE.index); oddCellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); evenCellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // set the sheet name to HSSF Test wb.setSheetName(0, title); for (short rownum = 0; rownum < (short) tableModel.getRowCount(); rownum++) { // create a row HSSFRow row = sheet.createRow(rownum + 1); for (short cellnum = (short) 0; cellnum < numColumns; cellnum++) { // create a numeric cell HSSFCell cell = row.createCell(cellnum); Object dataVal = tableModel.getValueAt(rownum, cellnum); cell.setCellValue(dataVal != null ? dataVal.toString() : ""); // on every other row cell.setCellStyle((rownum % 2) == 0 ? evenCellStyle : oddCellStyle); } } // write the workbook to the output stream // close our file (don't blow out our file handles wb.write(out); out.close(); } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(TableModel2Excel.class, ex); log.error("convertToExcel", ex); //$NON-NLS-1$ } } return toFile; }