List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet getRow
@Override public HSSFRow getRow(int rowIndex)
From source file:com.selfsoft.business.service.impl.TbFixEntrustServiceImpl.java
public void printTbFixEntrustTemplateXTL(OutputStream os, String tpl, Long tbFixEntrustId) { try {//ww w . j av a 2 s. c o m TbFixEntrust tbFixEntrust = this.findById(tbFixEntrustId); TbCustomer tbCustomer = tbCustomerService.findById(tbFixEntrust.getTbCustomer().getId()); TbCarInfo tbCarInfo = tbCarInfoService.findById(tbFixEntrust.getTbCarInfo().getId()); List<TbFixEntrustContent> tbFixEntrustContentList = this.composeContent( tbFixEntrustContentService.findTbFixEnTrustContentListByTbFixEntrustId(tbFixEntrustId)); // ?? TmCompany tmCompany = tmCompanyService.acquireUniqueTmCompany(); /* * List<TbMaintainPartContent> maintainList = * tbMaintainPartContentService * .getViewEntrustMaintianContent(tbFixEntrustId); * * * List<TmStockOutDetVo> solePartList = * tmStockOutService.getSellByEntrustCode * (tbFixEntrust.getEntrustCode()); */ /** * ?? */ List<TbMaintianVo> maintianvos = tbMaintainPartContentService .getTbMaintianDetailVosByEntrustId(tbFixEntrust.getId(), Constants.BALANCE_ALL); /** * ? */ List<TmStockOutDetVo> tmStockOutDetVos = tmStockOutService .getSellDetailByEntrustCode(tbFixEntrust.getEntrustCode(), Constants.BALANCE_ALL); /** * ?? */ List<TbMaintianVo> partAll = new ArrayList<TbMaintianVo>(); if (null != maintianvos && maintianvos.size() > 0) { for (TbMaintianVo tbMaintianVo : maintianvos) { partAll.add(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()); partAll.add(tbMaintianVo); } } partAll = this.composePart(partAll); int fixSize = (tbFixEntrustContentList == null ? 0 : tbFixEntrustContentList.size()); int maintainSize = (maintianvos == null ? 0 : maintianvos.size()); int solePartSize = (tmStockOutDetVos == null ? 0 : tmStockOutDetVos.size()); int partAllSize = (partAll == null ? 0 : partAll.size()); 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); HSSFRow row = null; HSSFCell cell = null; row = sheet.getRow(3); cell = row.getCell(0); cell.setCellValue(" ??:" + "?" + " (?:70691M) ?:" + tmCompany.getCompanyAddress() + " ?: " + (tmCompany.getCompanyPhone() == null ? "" : tmCompany.getCompanyPhone())); row = sheet.getRow(0); cell = row.getCell(31); cell.setCellStyle(style); cell.setCellValue("*?:" + tbCustomer.getCustomerCode() + "\n" + "??:"); row = sheet.getRow(6); cell = row.getCell(4); cell.setCellValue(tbCustomer.getCustomerName() == null ? "" : tbCustomer.getCustomerName()); row = sheet.getRow(6); cell = row.getCell(24); cell.setCellStyle(style); cell.setCellValue(tbCustomer.getAddress() == null ? "" : tbCustomer.getAddress()); row = sheet.getRow(6); cell = row.getCell(41); cell.setCellValue(tbCustomer.getContractPerson() == null ? "" : tbCustomer.getContractPerson()); row = sheet.getRow(8); cell = row.getCell(41); cell.setCellValue(tbCustomer.getTelephone() == null ? "" : tbCustomer.getTelephone()); row = sheet.getRow(8); cell = row.getCell(4); cell.setCellValue(tbCustomer.getTelephone() == null ? "" : tbCustomer.getTelephone()); row = sheet.getRow(12); cell = row.getCell(0); String entrustCode = tbFixEntrust.getEntrustCode(); String[] es = entrustCode.split("-"); String newCode = "RO" + es[0].substring(2, 6) + es[1]; cell.setCellValue(/* tbFixEntrust.getEntrustCode() */newCode); row = sheet.getRow(12); cell = row.getCell(9); cell.setCellValue(CommonMethod.parseDateToString(tbFixEntrust.getFixDate(), "yyyy-MM-dd HH:mm")); row = sheet.getRow(12); cell = row.getCell(18); cell.setCellValue(tbCarInfo.getLicenseCode()); row = sheet.getRow(12); cell = row.getCell(26); cell.setCellStyle(style); cell.setCellValue(tbCarInfo.getTmCarModelType().getModelName()); row = sheet.getRow(12); cell = row.getCell(34); cell.setCellValue(tbCarInfo.getChassisCode()); // ? row = sheet.getRow(16); cell = row.getCell(0); cell.setCellValue(""); row = sheet.getRow(16); cell = row.getCell(9); cell.setCellValue(CommonMethod.parseDateToString(tbCarInfo.getPurchaseDate(), "yyyy-MM-dd")); // ? row = sheet.getRow(16); cell = row.getCell(18); cell.setCellValue(""); row = sheet.getRow(16); cell = row.getCell(26); cell.setCellValue(tbFixEntrust.getEnterStationKilo() == null ? "" : new BigDecimal(tbFixEntrust.getEnterStationKilo().toString()) .divide(new BigDecimal("1.00"), 0, BigDecimal.ROUND_HALF_UP).toString()); row = sheet.getRow(16); cell = row.getCell(34); cell.setCellValue(CommonMethod.parseDateToString(tbFixEntrust.getEstimateDate(), "yyyy-MM-dd HH:mm")); Double fixCount = tbFixEntrustContentService.countTbFixEnTrustContentByTbFixEntrustId(tbFixEntrustId); row = sheet.getRow(75); cell = row.getCell(30); cell.setCellValue(new BigDecimal(fixCount).divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP) .toString()); BigDecimal partPriceAll = new BigDecimal("0.00"); if (partAllSize > 0) { for (int i = 0; i < partAllSize; i++) { TbMaintianVo tbMaintianVo = partAll.get(i); BigDecimal total = new BigDecimal(tbMaintianVo.getPrice()) .multiply(new BigDecimal(tbMaintianVo.getPartQuantity())); partPriceAll = partPriceAll.add(total); } } row = sheet.getRow(77); cell = row.getCell(30); cell.setCellValue(partPriceAll.divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); BigDecimal total = new BigDecimal(fixCount).add(partPriceAll).divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP); row = sheet.getRow(81); cell = row.getCell(30); cell.setCellValue(total.toString()); row = sheet.getRow(79); cell = row.getCell(30); cell.setCellValue("0.00"); ByteArrayOutputStream byteArrayOutImgLion = new ByteArrayOutputStream(); ByteArrayOutputStream byteArrayOutDBZF = new ByteArrayOutputStream(); BufferedImage bufferImgLion = ImageIO.read(this.getClass().getResourceAsStream("/xtl.png")); BufferedImage bufferImgDFBZ = ImageIO.read(this.getClass().getResourceAsStream("/xtl_logo.png")); ImageIO.write(bufferImgLion, "png", byteArrayOutImgLion); ImageIO.write(bufferImgDFBZ, "png", byteArrayOutDBZF); HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); HSSFClientAnchor anchorLion = new HSSFClientAnchor(0, 0, 1023, 200, (short) 40, 0, (short) 47, 2); HSSFClientAnchor anchorDBZF = new HSSFClientAnchor(0, 0, 1023, 100, (short) 0, 0, (short) 3, 3); patriarch.createPicture(anchorLion, workbook.addPicture(byteArrayOutImgLion.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); patriarch.createPicture(anchorDBZF, workbook.addPicture(byteArrayOutDBZF.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); int page = 1; if (fixSize / 8 >= (maintainSize + solePartSize) / 12) { page = fixSize / 8; } else { page = (maintainSize + solePartSize) / 12; } for (int i = 0; i < page; i++) { int p = 0; int k = 0; HSSFSheet sheetClone = workbook.cloneSheet(0); byteArrayOutImgLion = new ByteArrayOutputStream(); byteArrayOutDBZF = new ByteArrayOutputStream(); bufferImgLion = ImageIO.read(this.getClass().getResourceAsStream("/xtl.png")); bufferImgDFBZ = ImageIO.read(this.getClass().getResourceAsStream("/xtl_logo.png")); ImageIO.write(bufferImgLion, "png", byteArrayOutImgLion); ImageIO.write(bufferImgDFBZ, "png", byteArrayOutDBZF); patriarch = sheetClone.createDrawingPatriarch(); anchorLion = new HSSFClientAnchor(0, 0, 1023, 200, (short) 40, 0, (short) 47, 2); anchorDBZF = new HSSFClientAnchor(0, 0, 1023, 200, (short) 0, 0, (short) 3, 3); patriarch.createPicture(anchorLion, workbook.addPicture(byteArrayOutImgLion.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); patriarch.createPicture(anchorDBZF, workbook.addPicture(byteArrayOutDBZF.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); if (fixSize > 8) { int printFixSize = (fixSize > (i + 2) * 8 ? (i + 2) * 8 : fixSize); for (int j = 8 * (i + 1); j < printFixSize; j++) { TbFixEntrustContent content = tbFixEntrustContentList.get(j); List<TbFixShare> tbFixShareList = tbFixShareService .findTbFixShareListByTbFixEntrustContentId(content.getId()); String fixPersons = ""; String workTypes = ""; if (null != tbFixShareList && tbFixShareList.size() > 0) { for (TbFixShare tbFixShare : tbFixShareList) { if (null != tbFixShare.getTmUser()) { TmUser tmUser = tmUserService.findById(tbFixShare.getTmUser().getId()); fixPersons += (tmUser.getUserRealName() == null || "".equals(tmUser.getUserRealName()) ? tmUser.getUserName() : tmUser.getUserRealName()) + " "; workTypes += (tmUser.getTmWorkType() == null ? "" : tmUser.getTmWorkType().getWorkName()) + " "; } } } row = sheetClone.getRow(23 + p * 2); cell = row.getCell(2); cell.setCellStyle(style); cell.setCellValue(content.getStationName()); cell = row.getCell(20); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(content.getFixHour()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(24); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(content.getWorkingHourPrice()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(28); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(content.getFixHourAll()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(34); cell.setCellStyle(style); cell.setCellValue(content.getProjectType() == null ? "" : content.getProjectType()); cell = row.getCell(40); cell.setCellStyle(style); cell.setCellValue(workTypes); cell = row.getCell(45); cell.setCellStyle(style); cell.setCellValue(fixPersons); p++; } } if (partAllSize > 12) { int prinPartSize = (partAllSize > (i + 2) * 12 ? (i + 2) * 12 : partAllSize); for (int j = 12 * (i + 1); j < prinPartSize; j++) { TbMaintianVo t = partAll.get(j); row = sheetClone.getRow(41 + k * 2); cell = row.getCell(2); cell.setCellStyle(style); cell.setCellValue(t.getPartCode()); cell = row.getCell(11); cell.setCellStyle(style); cell.setCellValue(t.getPartName()); cell = row.getCell(20); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(t.getPartQuantity()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(24); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(t.getPrice()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(28); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(t.getPartQuantity()).multiply(new BigDecimal(t.getPrice())) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(34); cell.setCellStyle(style); cell.setCellValue(t.getProjectType() == null ? "" : t.getProjectType()); // cell = row.getCell(40); cell.setCellStyle(style); cell.setCellValue(""); k++; } } } if (fixSize > 0) { int printFixSize = (fixSize > 8 ? 8 : fixSize); for (int j = 0; j < printFixSize; j++) { TbFixEntrustContent content = tbFixEntrustContentList.get(j); List<TbFixShare> tbFixShareList = tbFixShareService .findTbFixShareListByTbFixEntrustContentId(content.getId()); String fixPersons = ""; String workTypes = ""; if (null != tbFixShareList && tbFixShareList.size() > 0) { for (TbFixShare tbFixShare : tbFixShareList) { if (null != tbFixShare.getTmUser()) { TmUser tmUser = tmUserService.findById(tbFixShare.getTmUser().getId()); fixPersons += (tmUser.getUserRealName() == null || "".equals(tmUser.getUserRealName()) ? tmUser.getUserName() : tmUser.getUserRealName()) + " "; workTypes += (tmUser.getTmWorkType() == null ? "" : tmUser.getTmWorkType().getWorkName()) + " "; } } } row = sheet.getRow(23 + j * 2); cell = row.getCell(2); cell.setCellStyle(style); cell.setCellValue(content.getStationName()); cell = row.getCell(20); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(content.getFixHour()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(24); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(content.getWorkingHourPrice()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(28); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(content.getFixHourAll()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(34); cell.setCellStyle(style); cell.setCellValue(content.getProjectType() == null ? "" : content.getProjectType()); cell = row.getCell(40); cell.setCellStyle(style); cell.setCellValue(workTypes); cell = row.getCell(45); cell.setCellStyle(style); cell.setCellValue(fixPersons); } } if (partAllSize > 0) { int printPartSize = (partAllSize > 12 ? 12 : partAllSize); for (int j = 0; j < printPartSize; j++) { TbMaintianVo t = partAll.get(j); row = sheet.getRow(41 + j * 2); cell = row.getCell(2); cell.setCellStyle(style); cell.setCellValue(t.getPartCode()); cell = row.getCell(11); cell.setCellStyle(style); cell.setCellValue(t.getPartName()); cell = row.getCell(20); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(t.getPartQuantity()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(24); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(t.getPrice()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(28); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(t.getPartQuantity()).multiply(new BigDecimal(t.getPrice())) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(34); cell.setCellStyle(style); cell.setCellValue(t.getProjectType() == null ? "" : t.getProjectType()); // cell = row.getCell(40); cell.setCellStyle(style); cell.setCellValue(""); } } workbook.write(os); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.selfsoft.business.service.impl.TbFixEntrustServiceImpl.java
public void printTbFixEntrustTemplateBlankXTL(OutputStream os, String tpl, Long tbFixEntrustId) { try {/*from ww w . j av a2s. co m*/ TbFixEntrust tbFixEntrust = this.findById(tbFixEntrustId); TbCustomer tbCustomer = tbCustomerService.findById(tbFixEntrust.getTbCustomer().getId()); TbCarInfo tbCarInfo = tbCarInfoService.findById(tbFixEntrust.getTbCarInfo().getId()); List<TbFixEntrustContent> tbFixEntrustContentList = tbFixEntrustContentService .findTbFixEnTrustContentListByTbFixEntrustId(tbFixEntrustId); // ?? TmCompany tmCompany = tmCompanyService.acquireUniqueTmCompany(); /* * List<TbMaintainPartContent> maintainList = * tbMaintainPartContentService * .getViewEntrustMaintianContent(tbFixEntrustId); * * * List<TmStockOutDetVo> solePartList = * tmStockOutService.getSellByEntrustCode * (tbFixEntrust.getEntrustCode()); */ /** * ?? */ List<TbMaintianVo> maintianvos = tbMaintainPartContentService .getTbMaintianDetailVosByEntrustId(tbFixEntrust.getId(), Constants.BALANCE_ALL); /** * ? */ List<TmStockOutDetVo> tmStockOutDetVos = tmStockOutService .getSellDetailByEntrustCode(tbFixEntrust.getEntrustCode(), Constants.BALANCE_ALL); /** * ?? */ List<TbMaintianVo> partAll = new ArrayList<TbMaintianVo>(); if (null != maintianvos && maintianvos.size() > 0) { for (TbMaintianVo tbMaintianVo : maintianvos) { partAll.add(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()); partAll.add(tbMaintianVo); } } int fixSize = (tbFixEntrustContentList == null ? 0 : tbFixEntrustContentList.size()); int maintainSize = (maintianvos == null ? 0 : maintianvos.size()); int solePartSize = (tmStockOutDetVos == null ? 0 : tmStockOutDetVos.size()); int partAllSize = (partAll == null ? 0 : partAll.size()); int pz = (fixSize / 8 > partAllSize / 12 ? (fixSize / 8 + 1) : (partAllSize / 12 + 1)); 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 style10_5 = workbook.createCellStyle(); style10_5.setWrapText(true); style10_5.setAlignment(HSSFCellStyle.ALIGN_LEFT); style10_5.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFFont font10_5 = workbook.createFont(); font10_5.setFontName(""); font10_5.setFontHeightInPoints((short) 11); style10_5.setFont(font10_5); HSSFRow row = null; HSSFCell cell = null; row = sheet.getRow(3); cell = row.getCell(0); cell.setCellValue(" ??:" + "?" + " (?:70691M) ?:" + tmCompany.getCompanyAddress() + " ?: " + (tmCompany.getCompanyPhone() == null ? "" : tmCompany.getCompanyPhone())); row = sheet.getRow(0); cell = row.getCell(40); // cell.setCellStyle(style); cell.setCellValue("*?:" + tbCustomer.getCustomerCode() + "\n" + "??:"); row = sheet.getRow(6); cell = row.getCell(4); cell.setCellValue(tbCustomer.getCustomerName() == null ? "" : tbCustomer.getCustomerName()); row = sheet.getRow(6); cell = row.getCell(24); // cell.setCellStyle(style); cell.setCellValue(tbCustomer.getAddress() == null ? "" : tbCustomer.getAddress()); row = sheet.getRow(6); cell = row.getCell(41); cell.setCellValue(tbCustomer.getContractPerson() == null ? "" : tbCustomer.getContractPerson()); row = sheet.getRow(8); cell = row.getCell(41); cell.setCellValue(tbCustomer.getTelephone() == null ? "" : tbCustomer.getTelephone()); row = sheet.getRow(8); cell = row.getCell(4); cell.setCellValue(tbCustomer.getTelephone() == null ? "" : tbCustomer.getTelephone()); row = sheet.getRow(12); cell = row.getCell(0); String entrustCode = tbFixEntrust.getEntrustCode(); String[] es = entrustCode.split("-"); String newCode = "RO" + es[0].substring(2, 6) + es[1]; cell.setCellValue(/* tbFixEntrust.getEntrustCode() */newCode); row = sheet.getRow(12); cell = row.getCell(9); cell.setCellValue(CommonMethod.parseDateToString(tbFixEntrust.getFixDate(), "yyyy-MM-dd HH:mm")); row = sheet.getRow(12); cell = row.getCell(18); cell.setCellValue(tbCarInfo.getLicenseCode()); row = sheet.getRow(12); cell = row.getCell(26); // cell.setCellStyle(style); cell.setCellValue(tbCarInfo.getTmCarModelType().getModelName()); row = sheet.getRow(12); cell = row.getCell(34); cell.setCellValue(tbCarInfo.getChassisCode()); // ? row = sheet.getRow(16); cell = row.getCell(0); cell.setCellValue(tbFixEntrust.getBjzzh() == null ? "" : tbFixEntrust.getBjzzh()); row = sheet.getRow(16); cell = row.getCell(9); cell.setCellValue(CommonMethod.parseDateToString(tbCarInfo.getPurchaseDate(), "yyyy-MM-dd")); // ? row = sheet.getRow(16); cell = row.getCell(18); cell.setCellValue(tbFixEntrust.getSbrq() == null ? "" : tbFixEntrust.getSbrq()); row = sheet.getRow(16); cell = row.getCell(26); cell.setCellValue(tbFixEntrust.getEnterStationKilo() == null ? "" : new BigDecimal(tbFixEntrust.getEnterStationKilo().toString()) .divide(new BigDecimal("1.00"), 0, BigDecimal.ROUND_HALF_UP).toString()); row = sheet.getRow(16); cell = row.getCell(34); cell.setCellValue(CommonMethod.parseDateToString(tbFixEntrust.getEstimateDate(), "yyyy-MM-dd HH:mm")); Double fixCount = tbFixEntrustContentService.countTbFixEnTrustContentByTbFixEntrustId(tbFixEntrustId); row = sheet.getRow(75); cell = row.getCell(30); cell.setCellValue(new BigDecimal(fixCount).divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP) .toString()); BigDecimal partPriceAll = new BigDecimal("0.00"); if (partAllSize > 0) { for (int i = 0; i < partAllSize; i++) { TbMaintianVo tbMaintianVo = partAll.get(i); BigDecimal total = new BigDecimal(tbMaintianVo.getPrice()) .multiply(new BigDecimal(tbMaintianVo.getPartQuantity())); partPriceAll = partPriceAll.add(total); } } row = sheet.getRow(77); cell = row.getCell(30); cell.setCellValue(partPriceAll.divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); BigDecimal total = new BigDecimal(fixCount).add(partPriceAll).divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP); row = sheet.getRow(81); cell = row.getCell(30); cell.setCellValue(total.toString()); row = sheet.getRow(79); cell = row.getCell(30); cell.setCellValue("0.00"); row = sheet.getRow(89); cell = row.getCell(6); cell.setCellValue("1"); row = sheet.getRow(89); cell = row.getCell(1); cell.setCellValue(pz + ""); int page = 1; if (fixSize / 8 >= (maintainSize + solePartSize) / 12) { page = fixSize / 8; } else { page = (maintainSize + solePartSize) / 12; } for (int i = 0; i < page; i++) { int p = 0; int k = 0; HSSFSheet sheetClone = workbook.cloneSheet(0); row = sheetClone.getRow(89); cell = row.getCell(1); cell.setCellValue((i + 1) + ""); row = sheetClone.getRow(89); cell = row.getCell(6); cell.setCellValue(pz + ""); if (fixSize > 8) { int printFixSize = (fixSize > (i + 2) * 8 ? (i + 2) * 8 : fixSize); for (int j = 8 * (i + 1); j < printFixSize; j++) { TbFixEntrustContent content = tbFixEntrustContentList.get(j); List<TbFixShare> tbFixShareList = tbFixShareService .findTbFixShareListByTbFixEntrustContentId(content.getId()); String fixPersons = ""; String workTypes = ""; if (null != tbFixShareList && tbFixShareList.size() > 0) { for (TbFixShare tbFixShare : tbFixShareList) { if (null != tbFixShare.getTmUser()) { TmUser tmUser = tmUserService.findById(tbFixShare.getTmUser().getId()); fixPersons += (tmUser.getUserRealName() == null || "".equals(tmUser.getUserRealName()) ? tmUser.getUserName() : tmUser.getUserRealName()) + " "; workTypes += (tmUser.getTmWorkType() == null ? "" : tmUser.getTmWorkType().getWorkName()) + " "; } } } row = sheetClone.getRow(23 + p * 2); cell = row.getCell(2); // cell.setCellStyle(style10_5); cell.setCellValue(content.getStationName()); cell = row.getCell(20); // cell.setCellStyle(style10_5); cell.setCellValue(new BigDecimal(content.getFixHour()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(24); // cell.setCellStyle(style10_5); cell.setCellValue(new BigDecimal(content.getWorkingHourPrice()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(28); // cell.setCellStyle(style10_5); cell.setCellValue(new BigDecimal(content.getFixHourAll()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(34); // cell.setCellStyle(style10_5); cell.setCellValue(content.getProjectType() == null ? "" : content.getProjectType()); cell = row.getCell(40); // cell.setCellStyle(style10_5); cell.setCellValue(workTypes); cell = row.getCell(45); // cell.setCellStyle(style10_5); cell.setCellValue(fixPersons); p++; } } if (partAllSize > 12) { int prinPartSize = (partAllSize > (i + 2) * 12 ? (i + 2) * 12 : partAllSize); for (int j = 12 * (i + 1); j < prinPartSize; j++) { TbMaintianVo t = partAll.get(j); row = sheetClone.getRow(41 + k * 2); cell = row.getCell(2); // cell.setCellStyle(style10_5); cell.setCellValue(t.getPartCode()); cell = row.getCell(11); // cell.setCellStyle(style10_5); cell.setCellValue(t.getPartName()); cell = row.getCell(20); // cell.setCellStyle(style10_5); cell.setCellValue(new BigDecimal(t.getPartQuantity()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(24); // cell.setCellStyle(style10_5); cell.setCellValue(new BigDecimal(t.getPrice()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(28); // cell.setCellStyle(style10_5); cell.setCellValue(new BigDecimal(t.getPartQuantity()).multiply(new BigDecimal(t.getPrice())) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(34); // cell.setCellStyle(style10_5); cell.setCellValue(t.getProjectType() == null ? "" : t.getProjectType()); // cell = row.getCell(40); // cell.setCellStyle(style10_5); cell.setCellValue(""); k++; } } } if (fixSize > 0) { int printFixSize = (fixSize > 8 ? 8 : fixSize); for (int j = 0; j < printFixSize; j++) { TbFixEntrustContent content = tbFixEntrustContentList.get(j); List<TbFixShare> tbFixShareList = tbFixShareService .findTbFixShareListByTbFixEntrustContentId(content.getId()); String fixPersons = ""; String workTypes = ""; if (null != tbFixShareList && tbFixShareList.size() > 0) { for (TbFixShare tbFixShare : tbFixShareList) { if (null != tbFixShare.getTmUser()) { TmUser tmUser = tmUserService.findById(tbFixShare.getTmUser().getId()); fixPersons += (tmUser.getUserRealName() == null || "".equals(tmUser.getUserRealName()) ? tmUser.getUserName() : tmUser.getUserRealName()) + " "; workTypes += (tmUser.getTmWorkType() == null ? "" : tmUser.getTmWorkType().getWorkName()) + " "; } } } row = sheet.getRow(23 + j * 2); cell = row.getCell(2); // cell.setCellStyle(style10_5); cell.setCellValue(content.getStationName()); cell = row.getCell(20); // cell.setCellStyle(style10_5); cell.setCellValue(new BigDecimal(content.getFixHour()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(24); // cell.setCellStyle(style10_5); cell.setCellValue(new BigDecimal(content.getWorkingHourPrice()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(28); // cell.setCellStyle(style10_5); cell.setCellValue(new BigDecimal(content.getFixHourAll()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(34); // cell.setCellStyle(style10_5); cell.setCellValue(content.getProjectType() == null ? "" : content.getProjectType()); cell = row.getCell(40); // cell.setCellStyle(style10_5); cell.setCellValue(workTypes); cell = row.getCell(45); // cell.setCellStyle(style10_5); cell.setCellValue(fixPersons); } } if (partAllSize > 0) { int printPartSize = (partAllSize > 12 ? 12 : partAllSize); for (int j = 0; j < printPartSize; j++) { TbMaintianVo t = partAll.get(j); row = sheet.getRow(41 + j * 2); cell = row.getCell(2); // cell.setCellStyle(style10_5); cell.setCellValue(t.getPartCode()); cell = row.getCell(11); // cell.setCellStyle(style10_5); cell.setCellValue(t.getPartName()); cell = row.getCell(20); // cell.setCellStyle(style10_5); cell.setCellValue(new BigDecimal(t.getPartQuantity()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(24); // cell.setCellStyle(style10_5); cell.setCellValue(new BigDecimal(t.getPrice()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(28); // cell.setCellStyle(style10_5); cell.setCellValue(new BigDecimal(t.getPartQuantity()).multiply(new BigDecimal(t.getPrice())) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(34); // cell.setCellStyle(style10_5); cell.setCellValue(t.getProjectType() == null ? "" : t.getProjectType()); // cell = row.getCell(40); // cell.setCellStyle(style10_5); cell.setCellValue(""); } } workbook.write(os); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.sevenorcas.openstyle.app.service.spreadsheet.SpreadSheetServiceImp.java
/** * Export sheet to workbook/* w w w . j a va 2 s. c om*/ * @param spreadSheet * @param workbook * @throws Exception */ private void exportSpreadSheet(List<SpreadSheet> sheets, HSSFWorkbook wb) throws Exception { for (SpreadSheet ss : sheets) { HSSFSheet sheet = wb.createSheet(ss.getSheetname()); ss.setWorkBook(wb); ss.createFreezePane(sheet); /*-*************************************************************** * Default column widths ****************************************************************/ for (int column = 0; column <= ss.getLastColumn(); column++) { if (ss.getColumnWidth(column) != -1) { sheet.setColumnWidth(column, ss.getColumnWidth(column)); } } /*-*************************************************************** * Output row data ****************************************************************/ for (int row = 0; row <= ss.getLastRow(); row++) { for (int column = 0; column <= ss.getLastColumn(); column++) { HSSFRow sheetRow = sheet.getRow(row); if (sheetRow == null) { sheetRow = sheet.createRow(row); } HSSFCell cell = sheetRow.createCell(column); SpreadsheetCell cellX = ss.getCell(column, row); if (cellX != null) { if (cellX.getCellRangeAddress() != null) { sheet.addMergedRegion(cellX.getCellRangeAddress()); } //Ex HSSFCellStyle style = cellX.getCellStyle(wb); cell.setCellStyle(style); boolean set = ss.getColumnWidth(column) == -1; if (set && cellX.isHeader() && cellX.getWidth() != null) { sheet.setColumnWidth(column, cellX.getWidth()); } cellX.setCellValue(cell, wb); } else { HSSFCellStyle style = ss.getCellStyleDefault(wb, row, column); cell.setCellStyle(style); } } } } }
From source file:com.siva.javamultithreading.ExcelUtil.java
private static void copySheets(HSSFWorkbook newWorkbook, HSSFSheet newSheet, HSSFSheet sheet, boolean copyStyle) { int newRownumber = newSheet.getLastRowNum() + 1; int maxColumnNum = 0; Map<Integer, HSSFCellStyle> styleMap = (copyStyle) ? new HashMap<Integer, HSSFCellStyle>() : null; for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) { HSSFRow srcRow = sheet.getRow(i); HSSFRow destRow = newSheet.createRow(i + newRownumber); if (srcRow != null) { copyRow(newWorkbook, sheet, newSheet, srcRow, destRow, styleMap); if (srcRow.getLastCellNum() > maxColumnNum) { maxColumnNum = srcRow.getLastCellNum(); }/* ww w .j av a 2 s . c o m*/ } } for (int i = 0; i <= maxColumnNum; i++) { newSheet.setColumnWidth(i, sheet.getColumnWidth(i)); } }
From source file:com.smanempat.controller.ControllerClassification.java
private void showXLS(JTextField txtFileDirectory, JTable tablePreview) throws FileNotFoundException, IOException { DefaultTableModel tableModel = new DefaultTableModel(); File fileName = new File(txtFileDirectory.getText()); FileInputStream inputStream = new FileInputStream(fileName); HSSFWorkbook workBook = new HSSFWorkbook(inputStream); HSSFSheet sheet = workBook.getSheetAt(0); int rowValue = sheet.getLastRowNum() + 1; int colValue = sheet.getRow(0).getLastCellNum(); String[][] data = new String[rowValue][colValue]; String[] colName = new String[colValue]; for (int i = 0; i < rowValue; i++) { HSSFRow row = sheet.getRow(i);/*from ww w . j a va 2 s . c o m*/ for (int j = 0; j < colValue; j++) { HSSFCell cell = row.getCell(j); int type = cell.getCellType(); Object returnCellValue = null; if (type == 0) { returnCellValue = cell.getNumericCellValue(); } else if (type == 1) { returnCellValue = cell.getStringCellValue(); } data[i][j] = returnCellValue.toString(); } } for (int i = 0; i < colValue; i++) { colName[i] = data[0][i]; } tableModel = new DefaultTableModel(data, colName); tablePreview.setModel(tableModel); tableModel.removeRow(0); }
From source file:com.softtek.mdm.web.admin.IndexController.java
private void exportExcel(String sheetName, String[] headNames, List<OrganizationModel> lists, HttpServletResponse response) {/*from w ww. j a va 2 s . c om*/ OutputStream out = null; try { HSSFWorkbook workbook = new HSSFWorkbook(); // HSSFSheet sheet = workbook.createSheet(sheetName); // // HSSFRow rowm = sheet.createRow(0); HSSFCell cellTiltle = rowm.createCell(0); //sheet??getColumnTopStyle()/getStyle()? - ? - ? HSSFCellStyle columnTopStyle = CommUtil.getColumnTopStyle(workbook);//?? sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, (headNames.length - 1))); cellTiltle.setCellStyle(columnTopStyle); cellTiltle.setCellValue(sheetName); // int columnNum = headNames.length; HSSFRow rowRowName = sheet.createRow(2); // 2?() // sheet? for (int n = 0; n < columnNum; n++) { HSSFCell cellRowName = rowRowName.createCell(n); //? cellRowName.setCellType(HSSFCell.CELL_TYPE_STRING); //?? HSSFRichTextString text = new HSSFRichTextString(headNames[n]); cellRowName.setCellValue(text); //? cellRowName.setCellStyle(columnTopStyle); //?? } //?sheet? HSSFDataFormat format = workbook.createDataFormat(); short formatDate = format.getFormat("yyyy-MM-dd hh:mm:ss"); for (int i = 0; i < lists.size(); i++) { HSSFRow row = sheet.createRow(i + 3);// OrganizationModel obj = lists.get(i);//??? /*row.createCell(0).setCellValue(obj.getOrgType());*/ row.createCell(0).setCellValue(obj.getName()); row.createCell(1).setCellValue(obj.getCreateName()); row.createCell(2).setCellValue(obj.getTotalUsers() == null ? 0 : obj.getTotalUsers()); row.createCell(3).setCellValue(obj.getTotalDevices() == null ? 0 : obj.getTotalDevices()); row.createCell(4).setCellValue(obj.getLicenseCount() == null ? 0 : obj.getLicenseCount()); row.createCell(5).setCellValue(obj.getUseUsers() == null ? 0 : obj.getUseUsers()); HSSFCell cell = row.createCell(6); cell.setCellValue(obj.getCreateTime()); HSSFCellStyle cellStyle = workbook.createCellStyle(); cellStyle.setDataFormat(formatDate); cell.setCellStyle(cellStyle); } //?? for (int colNum = 0; colNum < columnNum; colNum++) { int columnWidth = sheet.getColumnWidth(colNum) / 256; for (int rowNum = 0; rowNum < sheet.getLastRowNum(); rowNum++) { HSSFRow currentRow; //? currentRow = (sheet.getRow(rowNum) == null) ? sheet.createRow(rowNum) : sheet.getRow(rowNum); if (currentRow.getCell(colNum) != null) { HSSFCell currentCell = currentRow.getCell(colNum); if (currentCell.getCellType() == HSSFCell.CELL_TYPE_STRING) { int length = currentCell.getStringCellValue().getBytes().length; if (columnWidth < length) { columnWidth = length; } } } } sheet.setColumnWidth(colNum, (colNum == 0) ? (columnWidth * 256) : ((columnWidth + 10) * 256)); } if (workbook != null) { try { String fileName = "Excel-" + String.valueOf(System.currentTimeMillis()).substring(4, 13) + ".xls"; String headStr = "attachment; filename=\"" + fileName + "\""; response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", headStr); out = response.getOutputStream(); workbook.write(out); } catch (IOException e) { logger.error(e.getMessage()); } finally { if (out != null) { out.close(); } } } } catch (Exception e) { logger.error(e.getMessage()); } }
From source file:com.ssic.education.provider.controller.ProSupplierController.java
@RequestMapping(value = "/excel") @ResponseBody//from w ww.jav a 2 s.c o m public ModelAndView exportExcel(SupplierDto supplierDto, HttpServletRequest request, HttpServletResponse response) { SessionInfo info = (SessionInfo) request.getSession().getAttribute(ConfigUtil.SESSIONINFONAME); if (info == null) { return null; } supplierDto.setReceiverId(info.getSupplierId()); SimpleDateFormat sdf = new SimpleDateFormat("yyyy.M.d"); Date date = new Date(); String filename = Tools.date2Str(date, "yyyyMMddHHmmss"); HSSFSheet sheet; HSSFCell cell; response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment;filename=" + filename + ".xls"); Workbook workbook = new HSSFWorkbook(); sheet = (HSSFSheet) workbook.createSheet(""); try { List<String> titles = new ArrayList<String>(); titles.add("????"); titles.add("???"); // titles.add("????"); // titles.add("??????"); titles.add("????"); titles.add("???"); // titles.add("?"); // titles.add("???"); titles.add("?"); titles.add("?"); int len = titles.size(); HSSFCellStyle headerStyle = (HSSFCellStyle) workbook.createCellStyle(); // ? headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); headerStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFFont headerFont = (HSSFFont) workbook.createFont(); // headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); headerFont.setFontHeightInPoints((short) 11); headerStyle.setFont(headerFont); short width = 20, height = 25 * 20; sheet.setDefaultColumnWidth(width); HSSFRow sheetRow = sheet.createRow(0); for (int i = 0; i < len; i++) { // String title = titles.get(i); cell = sheetRow.createCell(i); cell.setCellStyle(headerStyle); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue(title); } sheet.getRow(0).setHeight(height); HSSFCellStyle contentStyle = (HSSFCellStyle) workbook.createCellStyle(); // ? contentStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); DataGrid dg = supplierService.findProSupplier(supplierDto, null); List<SupplierDto> expList = dg.getRows(); List<PageData> varList = new ArrayList<PageData>(); if (!CollectionUtils.isEmpty(expList)) { for (int i = 0; i < expList.size(); i++) { PageData vpd = new PageData(); vpd.put("var1", expList.get(i).getSupplierName()); vpd.put("var2", expList.get(i).getAddress()); // vpd.put("var3", expList.get(i).getFoodServiceCode()); // vpd.put("var4", expList.get(i).getFoodBusinessCode()); vpd.put("var3", expList.get(i).getFoodCirculationCode()); vpd.put("var4", expList.get(i).getFoodProduceCode()); // vpd.put("var7", expList.get(i).getBusinessLicense()); // vpd.put("var8", expList.get(i).getSupplierCode()); vpd.put("var5", expList.get(i).getCorporation()); vpd.put("var6", expList.get(i).getContactWay()); varList.add(vpd); } } for (int i = 0; i < varList.size(); i++) { HSSFRow row = sheet.createRow(i + 1); PageData vpd = varList.get(i); for (int j = 0; j < len; j++) { String varstr = vpd.getString("var" + (j + 1)) != null ? vpd.getString("var" + (j + 1)) : ""; cell = row.createCell(j); HSSFCellStyle cellStyle2 = (HSSFCellStyle) workbook.createCellStyle(); HSSFDataFormat format = (HSSFDataFormat) workbook.createDataFormat(); cellStyle2.setDataFormat(format.getFormat("@")); cell.setCellStyle(cellStyle2); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue(varstr); } } OutputStream os = response.getOutputStream(); workbook.write(os); os.flush(); os.close(); } catch (Exception e) { } return null; }
From source file:com.ssic.education.provider.controller.WaresController.java
@RequestMapping(value = "/excel") @ResponseBody/* w w w. j a v a 2s .c om*/ public ModelAndView exportExcel(ProWaresDto proWaresDto, HttpServletRequest request, HttpServletResponse response) { SessionInfo info = (SessionInfo) request.getSession().getAttribute(ConfigUtil.SESSIONINFONAME); if (info == null) { return null; } proWaresDto.setSupplierId(info.getSupplierId()); SimpleDateFormat sdf = new SimpleDateFormat("yyyy.M.d"); Date date = new Date(); String filename = Tools.date2Str(date, "yyyyMMddHHmmss"); HSSFSheet sheet; HSSFCell cell; response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment;filename=" + filename + ".xls"); Workbook workbook = new HSSFWorkbook(); sheet = (HSSFSheet) workbook.createSheet(""); try { List<String> titles = new ArrayList<String>(); titles.add("??"); titles.add("???"); titles.add(""); titles.add("?"); titles.add("?"); // titles.add("??"); // titles.add("???"); // titles.add("??"); titles.add("?"); titles.add("???"); titles.add(""); int len = titles.size(); HSSFCellStyle headerStyle = (HSSFCellStyle) workbook.createCellStyle(); // ? headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); headerStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFFont headerFont = (HSSFFont) workbook.createFont(); // headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); headerFont.setFontHeightInPoints((short) 11); headerStyle.setFont(headerFont); short width = 20, height = 25 * 20; sheet.setDefaultColumnWidth(width); HSSFRow sheetRow = sheet.createRow(0); for (int i = 0; i < len; i++) { // String title = titles.get(i); cell = sheetRow.createCell(i); cell.setCellStyle(headerStyle); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue(title); } sheet.getRow(0).setHeight(height); HSSFCellStyle contentStyle = (HSSFCellStyle) workbook.createCellStyle(); // ? contentStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); List<ProWaresDto> expList = waresService.findAllWares(proWaresDto, null); List<PageData> varList = new ArrayList<PageData>(); if (!CollectionUtils.isEmpty(expList)) { for (int i = 0; i < expList.size(); i++) { PageData vpd = new PageData(); vpd.put("var1", expList.get(i).getWaresName()); vpd.put("var2", expList.get(i).getAmountUnit()); vpd.put("var3", expList.get(i).getSpec()); vpd.put("var4", ProductClass.getName(expList.get(i).getWaresType())); vpd.put("var5", expList.get(i).getManufacturer()); // vpd.put("var5", expList.get(i).getEnName()); // vpd.put("var6", expList.get(i).getBarCode()); // vpd.put("var7", expList.get(i).getCustomCode()); vpd.put("var6", expList.get(i).getShelfLife()); vpd.put("var7", expList.get(i).getUnit()); vpd.put("var8", expList.get(i).getPlace()); varList.add(vpd); } } for (int i = 0; i < varList.size(); i++) { HSSFRow row = sheet.createRow(i + 1); PageData vpd = varList.get(i); for (int j = 0; j < len; j++) { String varstr = vpd.getString("var" + (j + 1)) != null ? vpd.getString("var" + (j + 1)) : ""; cell = row.createCell(j); HSSFCellStyle cellStyle2 = (HSSFCellStyle) workbook.createCellStyle(); HSSFDataFormat format = (HSSFDataFormat) workbook.createDataFormat(); cellStyle2.setDataFormat(format.getFormat("@")); cell.setCellStyle(cellStyle2); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue(varstr); } } OutputStream os = response.getOutputStream(); workbook.write(os); os.flush(); os.close(); } catch (Exception e) { } return null; }
From source file:com.syncnapsis.utils.data.ExcelHelper.java
License:Open Source License
public static void main(String[] args) throws Exception { String fileName = "testdata.xls"; HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream("src/main/resources/" + fileName)); HSSFSheet sheet = workbook.getSheet("Benutzer"); HSSFRow row = sheet.getRow(0); Cell cell;//from w w w. j a va 2 s . com for (int i = 2; i < 256; i++) { try { cell = row.getCell(i); if (cell == null) cell = row.createCell(i); cell.setCellFormula("IF(ISBLANK(Benutzer!A" + (i - 1) + "),\"\",Benutzer!A" + (i - 1) + ")"); } catch (Exception e) { e.printStackTrace(); } } workbook.write(new FileOutputStream("src/main/resources/new.xls")); }
From source file:com.syncnapsis.utils.data.UniverseEvolutionExcelParser.java
License:Open Source License
/** * Laden der Spalten fr die Kontakt-Rechte * //from w w w . j av a2s . co m * @param workbook - das Workbook * @param key_sheet_authorities_c - der Key fr das Sheet */ public static void parseContactAuthorities(HSSFWorkbook workbook, String key_sheet_authorities_c) { HSSFSheet sheet_authorities_c = workbook.getSheet(key_sheet_authorities_c); // sheet_authorities_c -> Laden der Spalten fr die Kontakt-Rechte HSSFRow row = sheet_authorities_c.getRow(0); for (int i = 1; i < 255; i++) { if (row.getCell(i) == null) break; contactAuthorities_colToName.put(i, row.getCell(i).getStringCellValue()); } logger.debug("contact-authority-columns loaded: " + contactAuthorities_colToName.size()); String name; // sheet_authorities_c -> Laden der Kontakt-Rechte int rowNum = 2; while ((row = sheet_authorities_c.getRow(rowNum++)) != null) { try { name = row.getCell(0).getStringCellValue(); contactAuthorities.put(name, new TreeMap<String, Boolean>()); for (int i = 1; i < 255; i++) { if (row.getCell(i) == null) break; contactAuthorities.get(name).put(contactAuthorities_colToName.get(i), row.getCell(i).getNumericCellValue() == 1); } } catch (Exception e) { e.printStackTrace(); logger.error("error: " + key_sheet_authorities_c + " at line " + rowNum); } } logger.debug("contact-authorities loaded: " + contactAuthorities.size()); }