List of usage examples for org.apache.poi.xssf.usermodel XSSFSheet createRow
@Override public XSSFRow createRow(int rownum)
From source file:com.frameworkset.platform.sanylog.common.POIExcelUtil2007.java
License:Open Source License
/** * Excel Workbook?.// w w w . j a va 2 s .com * * @param colDesc 1717?:user_id,??:user_name,:type_name" * @param dataList * @return * @author gw_liaozh * @throws InvocationTargetException * @throws IllegalAccessException * @throws IllegalArgumentException */ public static XSSFWorkbook createHSSFWorkbook(String colDesc, List<?> dataList) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { //???1717 //TODO: ? List<String> colTitleList = getColumnTitleList(colDesc); List<String> colFieldList = getColumnFieldList(colDesc); XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = wb.createSheet(); XSSFFont font = getBaseFont(wb); XSSFCellStyle headCellStyle = getHeadCellStyle(wb, font); //? CellStyle dateCellStyle = getDateTimeCellStyle(wb); //CellStyle strCellStyle = getStringCellStyle(wb); //??1717 XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper(sheet); Map<String, Class<?>> fieldTypeMap = new HashMap<String, Class<?>>(); // XSSFRow titleRow = sheet.createRow(0); for (int i = 0; i < colTitleList.size(); i++) { XSSFCell cell = titleRow.createCell(i); cell.setCellStyle(headCellStyle); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue(colTitleList.get(i)); } //?1717 for (int i = 0; i < dataList.size(); i++) { Object obj = dataList.get(i); XSSFRow row = sheet.createRow(i + 1); for (int j = 0; j < colFieldList.size(); j++) { String fieldName = colFieldList.get(j); XSSFCell cell = row.createCell(j); if (obj == null) { continue; } Object value = BeanConvertUtil.getProperty(obj, fieldName); //ClassInfo classInfo = ClassUtil.getClassInfo(obj.getClass()); //Object value = classInfo.getPropertyDescriptor(fieldName).getValue(obj); if (value == null) { continue; } //?? if (value instanceof Number) { cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(((Number) value).doubleValue()); } else if (value instanceof Date) { cell.setCellStyle(dateCellStyle); cell.setCellValue((Date) value); } else { cell.setCellType(HSSFCell.CELL_TYPE_STRING); //cell.setCellStyle(strCellStyle); cell.setCellValue(value.toString()); } fieldTypeMap.put(fieldName, value.getClass()); } } //?? for (int i = 0; i < colFieldList.size(); i++) { String fieldName = colFieldList.get(i); Class<?> fieldClass = fieldTypeMap.get(fieldName); if (fieldClass == null) { continue; } CellRangeAddressList range = new CellRangeAddressList(1, 65535, i, i); DataValidationConstraint constraint = null; if (Integer.class.isAssignableFrom(fieldClass)) { constraint = dvHelper.createIntegerConstraint(DataValidationConstraint.OperatorType.NOT_BETWEEN, "0", "-1"); sheet.addValidationData(dvHelper.createValidation(constraint, range)); } else if (Number.class.isAssignableFrom(fieldClass)) { constraint = dvHelper.createNumericConstraint(DataValidationConstraint.ValidationType.DECIMAL, DataValidationConstraint.OperatorType.NOT_BETWEEN, "0", "-1"); sheet.addValidationData(dvHelper.createValidation(constraint, range)); } else if (Date.class.isAssignableFrom(fieldClass)) { constraint = dvHelper.createDateConstraint(DataValidationConstraint.OperatorType.NOT_BETWEEN, "0000-01-02", "0000-01-01", "yyyy-MM-dd"); sheet.addValidationData(dvHelper.createValidation(constraint, range)); } } // for (int i = 0; i < colTitleList.size(); i++) { //?? //sheet.autoSizeColumn(i); } return wb; }
From source file:com.frameworkset.platform.util.POIExcelUtil.java
License:Open Source License
/** * Excel Workbook?.//from w w w . j ava2 s . c o m * * @param colDesc * "?:user_id,??:user_name,:type_name" * @param dataList * @return * @author gw_liaozh * @throws InvocationTargetException * @throws IllegalAccessException * @throws IllegalArgumentException */ public static XSSFWorkbook createHSSFWorkbook(List<String> titlesList, List<?> dataList) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { // ??? List<String> colFieldList = getColumnFieldList(titlesList); XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = wb.createSheet(); XSSFFont font = getBaseFont(wb); XSSFCellStyle headCellStyle = getHeadCellStyle(wb, font); // ? CellStyle dateCellStyle = getDateTimeCellStyle(wb); // ??1717 XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper(sheet); Map<String, Class<?>> fieldTypeMap = new HashMap<String, Class<?>>(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); // XSSFRow titleRow = sheet.createRow(0); for (int i = 0; i < titlesList.size(); i++) { XSSFCell cell = titleRow.createCell(i); cell.setCellStyle(headCellStyle); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue(titlesList.get(i)); } ClassInfo classInfo = null; // ? for (int i = 0; i < dataList.size(); i++) { Object obj = dataList.get(i); if (classInfo == null) classInfo = ClassUtil.getClassInfo(obj.getClass()); XSSFRow row = sheet.createRow(i + 1); for (int j = 0; j < colFieldList.size(); j++) { String fieldName = colFieldList.get(j); XSSFCell cell = row.createCell(j); if (obj == null) { continue; } PropertieDescription reflexField = classInfo.getPropertyDescriptor(fieldName); Object value = reflexField.getValue(obj); // ClassInfo classInfo = ClassUtil.getClassInfo(obj.getClass()); // Object value = classInfo.getPropertyDescriptor(fieldName).getValue(obj); if (value == null) { continue; } // ?? if (value instanceof Number) { cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(((Number) value).doubleValue()); } else if (value instanceof Date || value instanceof Timestamp) { cell.setCellStyle(dateCellStyle); cell.setCellValue(sdf.format((Date) value)); } else { cell.setCellType(HSSFCell.CELL_TYPE_STRING); // cell.setCellStyle(strCellStyle); cell.setCellValue(value.toString()); } fieldTypeMap.put(fieldName, value.getClass()); } } // ?? for (int i = 0; i < colFieldList.size(); i++) { String fieldName = colFieldList.get(i); Class<?> fieldClass = fieldTypeMap.get(fieldName); if (fieldClass == null) { continue; } CellRangeAddressList range = new CellRangeAddressList(1, 65535, i, i); DataValidationConstraint constraint = null; if (Integer.class.isAssignableFrom(fieldClass)) { constraint = dvHelper.createIntegerConstraint(DataValidationConstraint.OperatorType.NOT_BETWEEN, "0", "-1"); sheet.addValidationData(dvHelper.createValidation(constraint, range)); } else if (Number.class.isAssignableFrom(fieldClass)) { constraint = dvHelper.createNumericConstraint(DataValidationConstraint.ValidationType.DECIMAL, DataValidationConstraint.OperatorType.NOT_BETWEEN, "0", "-1"); sheet.addValidationData(dvHelper.createValidation(constraint, range)); } else if (Date.class.isAssignableFrom(fieldClass)) { constraint = dvHelper.createDateConstraint(DataValidationConstraint.OperatorType.NOT_BETWEEN, "0000-01-02", "0000-01-01", "yyyy-MM-dd"); sheet.addValidationData(dvHelper.createValidation(constraint, range)); } } // for (int i = 0; i < titlesList.size(); i++) { // ?? sheet.autoSizeColumn(i); } return wb; }
From source file:com.frameworkset.platform.util.POIExcelUtil2007.java
License:Open Source License
/** * Excel Workbook?./*from w ww. j a va2 s . c o m*/ * * @param colDesc ?:user_id,??:user_name,:type_name" * @param dataList * @return * @author gw_liaozh * @throws InvocationTargetException * @throws IllegalAccessException * @throws IllegalArgumentException */ public static XSSFWorkbook createHSSFWorkbook(String colDesc, List<?> dataList) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { //??? //TODO: ? List<String> colTitleList = getColumnTitleList(colDesc); List<String> colFieldList = getColumnFieldList(colDesc); XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = wb.createSheet(); XSSFFont font = getBaseFont(wb); XSSFCellStyle headCellStyle = getHeadCellStyle(wb, font); //? CellStyle dateCellStyle = getDateTimeCellStyle(wb); //CellStyle strCellStyle = getStringCellStyle(wb); //?? XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper(sheet); Map<String, Class<?>> fieldTypeMap = new HashMap<String, Class<?>>(); // XSSFRow titleRow = sheet.createRow(0); for (int i = 0; i < colTitleList.size(); i++) { XSSFCell cell = titleRow.createCell(i); cell.setCellStyle(headCellStyle); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue(colTitleList.get(i)); } //? for (int i = 0; i < dataList.size(); i++) { Object obj = dataList.get(i); XSSFRow row = sheet.createRow(i + 1); for (int j = 0; j < colFieldList.size(); j++) { String fieldName = colFieldList.get(j); XSSFCell cell = row.createCell(j); if (obj == null) { continue; } Object value = BeanConvertUtil.getProperty(obj, fieldName); //ClassInfo classInfo = ClassUtil.getClassInfo(obj.getClass()); //Object value = classInfo.getPropertyDescriptor(fieldName).getValue(obj); if (value == null) { continue; } //?? if (value instanceof Number) { cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(((Number) value).doubleValue()); } else if (value instanceof Date) { cell.setCellStyle(dateCellStyle); cell.setCellValue((Date) value); } else { cell.setCellType(HSSFCell.CELL_TYPE_STRING); //cell.setCellStyle(strCellStyle); cell.setCellValue(value.toString()); } fieldTypeMap.put(fieldName, value.getClass()); } } //?? for (int i = 0; i < colFieldList.size(); i++) { String fieldName = colFieldList.get(i); Class<?> fieldClass = fieldTypeMap.get(fieldName); if (fieldClass == null) { continue; } CellRangeAddressList range = new CellRangeAddressList(1, 65535, i, i); DataValidationConstraint constraint = null; if (Integer.class.isAssignableFrom(fieldClass)) { constraint = dvHelper.createIntegerConstraint(DataValidationConstraint.OperatorType.NOT_BETWEEN, "0", "-1"); sheet.addValidationData(dvHelper.createValidation(constraint, range)); } else if (Number.class.isAssignableFrom(fieldClass)) { constraint = dvHelper.createNumericConstraint(DataValidationConstraint.ValidationType.DECIMAL, DataValidationConstraint.OperatorType.NOT_BETWEEN, "0", "-1"); sheet.addValidationData(dvHelper.createValidation(constraint, range)); } else if (Date.class.isAssignableFrom(fieldClass)) { constraint = dvHelper.createDateConstraint(DataValidationConstraint.OperatorType.NOT_BETWEEN, "0000-01-02", "0000-01-01", "yyyy-MM-dd"); sheet.addValidationData(dvHelper.createValidation(constraint, range)); } } // for (int i = 0; i < colTitleList.size(); i++) { //?? //sheet.autoSizeColumn(i); } return wb; }
From source file:com.FuntionLibrary.java
public void writetoExcel(String Name, String EmailId, String Password, String MobileNo, XSSFSheet sheet, String MailPaswd) throws InvalidFormatException, IOException { try {//from w ww .j a v a2 s. c o m //String excelFileName = "";//name of excel file int r = sheet.getLastRowNum(); XSSFRow r1 = sheet.createRow(0); XSSFCell Srnocell = r1.createCell(0); Srnocell.setCellValue("Name"); XSSFCell actioncell = r1.createCell(1); actioncell.setCellValue("EmailId"); XSSFCell loccell = r1.createCell(2); loccell.setCellValue("Password"); XSSFCell valuecell = r1.createCell(3); valuecell.setCellValue("Mobile Number"); XSSFCell EmailPassword = r1.createCell(4); EmailPassword.setCellValue("Email Password"); XSSFRow row = sheet.createRow(r + 1); //iterating c number of columns XSSFCell cell = row.createCell(0); cell.setCellValue(Name); System.out.println(Name); XSSFCell cell1 = row.createCell(1); cell1.setCellValue(EmailId); System.out.println(EmailId); XSSFCell cell2 = row.createCell(2); cell2.setCellValue(Password); System.out.println(Password); XSSFCell cell3 = row.createCell(3); cell3.setCellValue(MobileNo); System.out.println(MobileNo); XSSFCell cell4 = row.createCell(4); cell4.setCellValue(MailPaswd); System.out.println(MailPaswd); } catch (Exception e) { JOptionPane.showMessageDialog(null, "Oops Something Went wrong Error - > " + e.getMessage()); } }
From source file:com.grant.report.StockOut.java
public static void main(String[] args) throws SQLException { ItemDAO d = new ItemDAO(); Map<String, Object[]> data = new TreeMap<String, Object[]>(); // data = d.getAllItemOutReport(); //Blank workbook XSSFWorkbook workbook = new XSSFWorkbook(); //Create a blank sheet XSSFSheet sheet = workbook.createSheet("Employee Data"); //This data needs to be written (Object[]) /*//from w w w. j a v a 2s . c o m Map<String, Object[]> data = new TreeMap<String, Object[]>(); data.put("1", new Object[] {"ID", "NAME", "LASTNAME"}); data.put("2", new Object[] {1, "Amit", "Shukla"}); data.put("3", new Object[] {2, "Lokesh", "Gupta"}); data.put("4", new Object[] {3, "John", "Adwards"}); data.put("5", new Object[] {4, "Brian", "Schultz"}); */ //Iterate over data and write to sheet Set<String> keyset = data.keySet(); int rownum = 0; for (String key : keyset) { Row row = sheet.createRow(rownum++); Object[] objArr = data.get(key); int cellnum = 0; for (Object obj : objArr) { Cell cell = row.createCell(cellnum++); if (obj instanceof String) { cell.setCellValue((String) obj); } else if (obj instanceof Integer) { cell.setCellValue((Integer) obj); } } } try { //Write the workbook in file system FileOutputStream out = new FileOutputStream(new File("howtodoinjava_demo.xlsx")); workbook.write(out); out.close(); System.out.println("howtodoinjava_demo.xlsx written successfully on disk."); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.griffinslogistics.document.excel.CMRGenerator.java
private static void generate(XSSFWorkbook workbook, BookspackageCMRModel bookspackageCMRModel, Pulsiodetails pulsioDetails) {/* ww w. j a v a 2 s . c om*/ //Get first sheet from the workbook XSSFSheet sheet = workbook.createSheet(bookspackageCMRModel.getPackageNumber()); setDefaultSheetStyles(sheet); Map<String, CellStyle> styles = createStyles(workbook); int currentRow = 2; Row headerRow = sheet.createRow(currentRow); generateHeaderRow(headerRow, styles, bookspackageCMRModel.getPackageNumber()); currentRow = generateSenderAndDriver(sheet, styles, currentRow); currentRow = generatePoint2Till9(sheet, styles, currentRow, bookspackageCMRModel.getDeliveryAddress()); double weight = bookspackageCMRModel.getTotalWeight(); Long totalBoxesCount = bookspackageCMRModel.getTotalBoxesCount(); currentRow = generatePoints10Till15(totalBoxesCount, weight, sheet, styles, currentRow); currentRow = generatePoint15Till19(sheet, styles, currentRow); currentRow = generatePoint20Till24(sheet, styles, currentRow, pulsioDetails); sheet.autoSizeColumn(1, false); sheet.autoSizeColumn(2, false); sheet.autoSizeColumn(7, false); sheet.autoSizeColumn(9, false); sheet.setFitToPage(true); }
From source file:com.griffinslogistics.document.excel.CMRGenerator.java
private static int generateSenderAndDriver(XSSFSheet sheet, Map<String, CellStyle> styles, int currentRow) { // new value is 5 currentRow = currentRow + 3;/* ww w . j ava 2 s. com*/ Row labelRow = sheet.createRow(currentRow); sheet.addMergedRegion(CellRangeAddress.valueOf("$B$6:$C6")); sheet.addMergedRegion(CellRangeAddress.valueOf("$B$7:$C7")); sheet.addMergedRegion(CellRangeAddress.valueOf("$B$8:$C8")); sheet.addMergedRegion(CellRangeAddress.valueOf("$B$9:$C9")); sheet.addMergedRegion(CellRangeAddress.valueOf("$B$10:$C10")); sheet.addMergedRegion(CellRangeAddress.valueOf("$D$6:$I$10")); Cell senderLabelCell = labelRow.createCell(1); senderLabelCell.setCellValue(LABEL_SENDER); senderLabelCell.setCellStyle(styles.get(LABEL_TOP_STYLE)); labelRow.createCell(2).setCellStyle(styles.get(LABEL_TOP_STYLE)); currentRow++; Row addressRow1 = sheet.createRow(currentRow); Cell addressCell1 = addressRow1.createCell(1); addressCell1.setCellValue(ADDRESS_PART_1); addressCell1.setCellStyle(styles.get(CONTENT_MIDDLE_STYLE)); currentRow++; Row addressRow2 = sheet.createRow(currentRow); Cell addressCell2 = addressRow2.createCell(1); addressCell2.setCellValue(ADDRESS_PART_2); addressCell2.setCellStyle(styles.get(CONTENT_MIDDLE_STYLE)); currentRow++; Row addressRow3 = sheet.createRow(currentRow); Cell addressCell3 = addressRow3.createCell(1); addressCell3.setCellValue(ADDRESS_PART_3); addressCell3.setCellStyle(styles.get(CONTENT_MIDDLE_STYLE)); currentRow++; Row addressRow4 = sheet.createRow(currentRow); Cell addressCell4 = addressRow4.createCell(1); addressCell4.setCellValue(ADDRESS_PART_4); addressCell4.setCellStyle(styles.get(CONTENT_BOTTOM_STYLE)); addressRow4.createCell(2).setCellStyle(styles.get(CONTENT_BOTTOM_STYLE)); //set styles for driver cells for (int i = 5; i <= 9; i++) { // the rows are already initialized above Row row = sheet.getRow(i); for (int j = 3; j <= 8; j++) { Cell cell = row.createCell(j); cell.setCellStyle(styles.get(LABEL_WHOLE_STYLE)); } } Cell driverCell = labelRow.createCell(3); driverCell.setCellValue(LABEL_DRIVER); driverCell.setCellStyle(styles.get(LABEL_WHOLE_STYLE)); return currentRow; }
From source file:com.griffinslogistics.document.excel.CMRGenerator.java
private static int generatePoint2Till9(XSSFSheet sheet, Map<String, CellStyle> styles, int currentRow, String deliveryAddress) { for (int i = 11; i < 27; i++) { sheet.addMergedRegion(CellRangeAddress.valueOf("$B$" + i + ":$C$" + i)); sheet.addMergedRegion(CellRangeAddress.valueOf("$D$" + i + ":$I$" + i)); }//from ww w. ja v a 2 s .c om currentRow++; Row row11 = sheet.createRow(currentRow); Cell receiverLabelCell = row11.createCell(1); receiverLabelCell.setCellValue(LABEL_RECEIVER); receiverLabelCell.setCellStyle(styles.get(LABEL_TOP_STYLE)); row11.createCell(2).setCellStyle(styles.get(LABEL_TOP_STYLE)); currentRow++; Row row12 = sheet.createRow(currentRow); row12.createCell(1).setCellStyle(styles.get(CONTENT_MIDDLE_STYLE)); row12.createCell(2).setCellStyle(styles.get(CONTENT_MIDDLE_STYLE)); currentRow++; Row row13 = sheet.createRow(currentRow); Cell receiverCell1 = row13.createCell(1); receiverCell1.setCellValue(RECEIVER_PART_1); receiverCell1.setCellStyle(styles.get(CONTENT_MIDDLE_STYLE)); row13.createCell(2).setCellStyle(styles.get(CONTENT_MIDDLE_STYLE)); currentRow++; Row row14 = sheet.createRow(currentRow); Cell receiverCell2 = row14.createCell(1); receiverCell2.setCellValue(RECEIVER_PART_2); receiverCell2.setCellStyle(styles.get(CONTENT_MIDDLE_STYLE)); row14.createCell(2).setCellStyle(styles.get(CONTENT_MIDDLE_STYLE)); row14.createCell(8).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); currentRow++; Row row15 = sheet.createRow(currentRow); Cell receiverCell3 = row15.createCell(1); receiverCell3.setCellValue(RECEIVER_PART_3); receiverCell3.setCellStyle(styles.get(CONTENT_MIDDLE_STYLE)); row15.createCell(2).setCellStyle(styles.get(CONTENT_MIDDLE_STYLE)); Cell successiveCarrierCell1 = row11.createCell(3); successiveCarrierCell1.setCellValue(LABEL_SUCCESSIVE_CARRIERS_PART_1); successiveCarrierCell1.setCellStyle(styles.get(LABEL_TOP_STYLE)); row11.createCell(8).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); Cell successiveCarrierCell2 = row12.createCell(3); successiveCarrierCell2.setCellValue(LABEL_SUCCESSIVE_CARRIERS_PART_2); successiveCarrierCell2.setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); row12.createCell(8).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); Cell successiveCarrierCell3 = row13.createCell(3); successiveCarrierCell3.setCellValue(LABEL_SUCCESSIVE_CARRIERS_PART_3); successiveCarrierCell3.setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); row13.createCell(8).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); Cell reservationsCell1 = row15.createCell(3); reservationsCell1.setCellValue(RESERVATIONS_PART_1); reservationsCell1.setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); row15.createCell(8).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); currentRow++; Row row16 = sheet.createRow(currentRow); Cell reservationsCell2 = row16.createCell(3); reservationsCell2.setCellValue(RESERVATIONS_PART_2); reservationsCell2.setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); row16.createCell(1).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); row16.createCell(2).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); row16.createCell(8).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); currentRow++; Row row17 = sheet.createRow(currentRow); row17.createCell(1).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); row17.createCell(2).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); row17.createCell(3).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); row17.createCell(8).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); currentRow++; Row row18 = sheet.createRow(currentRow); Cell takingOverCellLabel = row18.createCell(1); takingOverCellLabel.setCellValue(LABEL_TAKING_OVER); takingOverCellLabel.setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); row18.createCell(2).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); row18.createCell(3).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); row18.createCell(8).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); currentRow++; Row row19 = sheet.createRow(currentRow); Cell takingOverContentCell = row19.createCell(1); takingOverContentCell.setCellStyle(styles.get(CONTENT_MIDDLE_STYLE)); takingOverContentCell.setCellValue(TAKING_OVER_CONTENT); row19.createCell(2).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); row19.createCell(3).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); row19.createCell(8).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); currentRow++; Row row20 = sheet.createRow(currentRow); Cell countryLabelCell = row20.createCell(1); countryLabelCell.setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); countryLabelCell.setCellValue(LABEL_COUNTRY); row20.createCell(2).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); row20.createCell(3).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); row20.createCell(8).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); currentRow++; Row row21 = sheet.createRow(currentRow); Cell countryContentCell = row21.createCell(1); countryContentCell.setCellStyle(styles.get(CONTENT_MIDDLE_STYLE)); countryContentCell.setCellValue(ADDRESS_PART_4.trim()); row21.createCell(2).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); row21.createCell(3).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); row21.createCell(8).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); currentRow++; Row row22 = sheet.createRow(currentRow); Cell dateCell = row22.createCell(1); dateCell.setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); dateCell.setCellValue(LABEL_DATE); row22.createCell(2).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); row22.createCell(3).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); row22.createCell(8).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); currentRow++; Row row23 = sheet.createRow(currentRow); Cell arrivalTime = row23.createCell(1); arrivalTime.setCellStyle(styles.get(LABEL_BOTTOM_STYLE)); arrivalTime.setCellValue(LABEL_ARRIVAL_TIME); row23.createCell(2).setCellStyle(styles.get(LABEL_BOTTOM_STYLE)); for (int i = 3; i < 9; i++) { row23.createCell(i).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); } currentRow++; Row row24 = sheet.createRow(currentRow); Cell goodsDeliveryLabelCell = row24.createCell(1); goodsDeliveryLabelCell.setCellValue(LABEL_DELIVERY_OF_GOODS); goodsDeliveryLabelCell.setCellStyle(styles.get(LABEL_TOP_STYLE)); row24.createCell(2).setCellStyle(styles.get(LABEL_TOP_STYLE)); currentRow++; Row row25 = sheet.createRow(currentRow); Cell placeLabelCell = row25.createCell(1); placeLabelCell.setCellValue(LABEL_PLACE); placeLabelCell.setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); row25.createCell(2).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); currentRow++; Row row26 = sheet.createRow(currentRow); row26.setHeight((short) 1500); Cell placeContentCell = row26.createCell(1); placeContentCell.setCellValue(deliveryAddress); placeContentCell.setCellStyle(styles.get(CONTENT_MIDDLE_STYLE)); row26.createCell(2).setCellStyle(styles.get(CONTENT_MIDDLE_STYLE)); currentRow++; Row row27 = sheet.createRow(currentRow); Cell deliveryCountryLabelCell = row27.createCell(1); deliveryCountryLabelCell.setCellValue(LABEL_COUNTRY); deliveryCountryLabelCell.setCellStyle(styles.get(LABEL_LEFT_STYLE)); Cell deliveryCountryContentCell = row27.createCell(2); deliveryCountryContentCell.setCellValue(FRANCE); deliveryCountryContentCell.setCellStyle(styles.get(CONTENT_RIGHT_STYLE)); currentRow++; Row row28 = sheet.createRow(currentRow); sheet.addMergedRegion(CellRangeAddress.valueOf("$B$28:$C$28")); Cell openingHoursCell = row28.createCell(1); openingHoursCell.setCellValue(LABEL_OPENING_HOURS); openingHoursCell.setCellStyle(styles.get(LABEL_BOTTOM_STYLE)); row28.createCell(2).setCellStyle(styles.get(LABEL_BOTTOM_STYLE)); currentRow++; Row row29 = sheet.createRow(currentRow); sheet.addMergedRegion(CellRangeAddress.valueOf("$B$29:$C$29")); sheet.addMergedRegion(CellRangeAddress.valueOf("$B$30:$C$30")); Cell senderInstructionsCell1 = row29.createCell(1); senderInstructionsCell1.setCellValue(SENDER_INSTRUCTIONS_BULGARIAN); senderInstructionsCell1.setCellStyle(styles.get(LABEL_TOP_STYLE)); row29.createCell(2).setCellStyle(styles.get(LABEL_TOP_STYLE)); sheet.addMergedRegion(CellRangeAddress.valueOf("$D$29:$I$29")); sheet.addMergedRegion(CellRangeAddress.valueOf("$D$30:$I$30")); Cell carrierDocumentsCell1 = row29.createCell(3); carrierDocumentsCell1.setCellValue(CARRIER_DOCUMENTS_BULGARIAN); carrierDocumentsCell1.setCellStyle(styles.get(LABEL_TOP_STYLE)); for (int i = 4; i < 9; i++) { row29.createCell(i).setCellStyle(styles.get(LABEL_TOP_STYLE)); } currentRow++; Row row30 = sheet.createRow(currentRow); Cell senderInstructionsCell2 = row30.createCell(1); senderInstructionsCell2.setCellValue(SENDERS_INSTRUCTIONS_ENGLISH); senderInstructionsCell2.setCellStyle(styles.get(LABEL_BOTTOM_STYLE)); row30.createCell(2).setCellStyle(styles.get(LABEL_BOTTOM_STYLE)); Cell carrierDocumentsCell2 = row30.createCell(3); carrierDocumentsCell2.setCellValue(CARRIER_DOCUMENTS_ENGLISH); carrierDocumentsCell2.setCellStyle(styles.get(LABEL_BOTTOM_STYLE)); for (int i = 4; i < 9; i++) { row30.createCell(i).setCellStyle(styles.get(LABEL_BOTTOM_STYLE)); } for (int i = 23; i < 28; i++) { sheet.getRow(i).createCell(8).setCellStyle(styles.get(LABEL_RIGHT_STYLE)); } return currentRow; }
From source file:com.griffinslogistics.document.excel.CMRGenerator.java
private static int generatePoints10Till15(Long totalBoxesCount, double weight, XSSFSheet sheet, Map<String, CellStyle> styles, int currentRow) { currentRow++;/*from w ww. j a v a 2s .co m*/ Row row31 = sheet.createRow(currentRow); sheet.addMergedRegion(CellRangeAddress.valueOf("$B$31:$E$31")); sheet.addMergedRegion(CellRangeAddress.valueOf("$F$31:$G$31")); sheet.addMergedRegion(CellRangeAddress.valueOf("$H$31:$I$31")); sheet.addMergedRegion(CellRangeAddress.valueOf("$B$32:$E$32")); sheet.addMergedRegion(CellRangeAddress.valueOf("$F$32:$G$32")); sheet.addMergedRegion(CellRangeAddress.valueOf("$H$32:$I$32")); Cell labels10Till13Cell = row31.createCell(1); labels10Till13Cell.setCellValue(LABELS_10_TILL_13_BULGARIAN); labels10Till13Cell.setCellStyle(styles.get(LABEL_TOP_STYLE)); Cell weightLabelCell1 = row31.createCell(5); weightLabelCell1.setCellValue(LABEL_WEIGHT_BULGARIAN); weightLabelCell1.setCellStyle(styles.get(LABEL_TOP_STYLE)); Cell volumeLabelCell1 = row31.createCell(7); volumeLabelCell1.setCellValue(LABEL_VOLUME); volumeLabelCell1.setCellStyle(styles.get(LABEL_TOP_STYLE)); row31.createCell(8).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); currentRow++; Row row32 = sheet.createRow(currentRow); Cell labels10Till13Cel2 = row32.createCell(1); labels10Till13Cel2.setCellValue(LABEL_10_TILL_13_ENGLISH); labels10Till13Cel2.setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); Cell weightLabelCell2 = row32.createCell(5); weightLabelCell2.setCellValue(LABEL_WEIGHT_ENGLISH); weightLabelCell2.setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); Cell volumeLabelCell2 = row32.createCell(7); volumeLabelCell2.setCellValue(LABEL_VOLUME_ENGLISH); volumeLabelCell2.setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); row32.createCell(8).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); // DYNAMIC CONTENT FOR BOOKS sheet.addMergedRegion(CellRangeAddress.valueOf("$D$33:$E$33")); sheet.addMergedRegion(CellRangeAddress.valueOf("$F$33:$G$33")); sheet.addMergedRegion(CellRangeAddress.valueOf("$H$33:$I$33")); currentRow++; Row row33 = sheet.createRow(currentRow); Cell packagesCountCell = row33.createCell(1); packagesCountCell.setCellValue(totalBoxesCount); packagesCountCell.setCellStyle(styles.get(CONTENT_MIDDLE_ALLIGN_RIGHT_STYLE)); Cell packagingMethodCell = row33.createCell(2); packagingMethodCell.setCellValue("CARTONS"); packagingMethodCell.setCellStyle(styles.get(CONTENT_MIDDLE_NO_BORDERS_STYLE)); Cell goodsNatureCell = row33.createCell(3); goodsNatureCell.setCellValue("BOOKS"); goodsNatureCell.setCellStyle(styles.get(CONTENT_MIDDLE_ALLIGN_CENTER_STYLE)); Cell grossWeightCell = row33.createCell(5); try { BigDecimal bd = new BigDecimal(weight); bd = bd.setScale(2, RoundingMode.HALF_UP); weight = bd.doubleValue(); } catch (Exception e) { System.out.println(e.getMessage()); } grossWeightCell.setCellValue(weight); grossWeightCell.setCellStyle(styles.get(CONTENT_MIDDLE_ALLIGN_CENTER_STYLE)); for (int j = 6; j <= 8; j++) { row33.createCell(j).setCellStyle(styles.get(CONTENT_MIDDLE_ALLIGN_CENTER_STYLE)); } currentRow++; Row totalsRow = sheet.createRow(currentRow); String cellMergeString = String.format("$B$%s:$E$%s", currentRow + 1, currentRow + 1); sheet.addMergedRegion(CellRangeAddress.valueOf(cellMergeString)); cellMergeString = String.format("$F$%s:$G$%s", currentRow + 1, currentRow + 1); sheet.addMergedRegion(CellRangeAddress.valueOf(cellMergeString)); cellMergeString = String.format("$H$%s:$I$%s", currentRow + 1, currentRow + 1); sheet.addMergedRegion(CellRangeAddress.valueOf(cellMergeString)); Cell totalsLabelCell = totalsRow.createCell(1); totalsLabelCell.setCellValue(LABEL_TOTALS_10_TILL_15); totalsLabelCell.setCellStyle(styles.get(LABEL_BOTTOM_STYLE)); for (int i = 2; i <= 4; i++) { totalsRow.createCell(i).setCellStyle(styles.get(LABEL_BOTTOM_STYLE)); } Cell totalWeightCell = totalsRow.createCell(5); totalWeightCell.setCellStyle(styles.get(CONTENT_BOTTOM_ALLIGN_CENTER_STYLE)); totalWeightCell.setCellFormula("SUM(F33)"); totalsRow.createCell(6).setCellStyle(styles.get(CONTENT_BOTTOM_ALLIGN_CENTER_STYLE)); Cell totalVolumeCell = totalsRow.createCell(7); totalVolumeCell.setCellStyle(styles.get(CONTENT_BOTTOM_ALLIGN_CENTER_STYLE)); totalVolumeCell.setCellFormula("SUM(H33)"); totalsRow.createCell(8).setCellStyle(styles.get(CONTENT_BOTTOM_ALLIGN_CENTER_STYLE)); return currentRow; }
From source file:com.griffinslogistics.document.excel.CMRGenerator.java
private static int generatePoint15Till19(XSSFSheet sheet, Map<String, CellStyle> styles, int currentRow) { currentRow++;/*from w w w . ja v a2 s . c o m*/ String mergeString; for (int i = currentRow; i < currentRow + 7; i++) { sheet.createRow(i).setHeightInPoints(25); mergeString = String.format("$B$%s:$C$%s", i + 1, i + 1); sheet.addMergedRegion(CellRangeAddress.valueOf(mergeString)); mergeString = String.format("$D$%s:$E$%s", i + 1, i + 1); sheet.addMergedRegion(CellRangeAddress.valueOf(mergeString)); mergeString = String.format("$F$%s:$G$%s", i + 1, i + 1); sheet.addMergedRegion(CellRangeAddress.valueOf(mergeString)); mergeString = String.format("$H$%s:$I$%s", i + 1, i + 1); sheet.addMergedRegion(CellRangeAddress.valueOf(mergeString)); } Row row35 = sheet.getRow(currentRow); Cell agreementsLabelCell1 = row35.createCell(1); agreementsLabelCell1.setCellValue(LABEL_AGREEMENTS_BULGARIAN); agreementsLabelCell1.setCellStyle(styles.get(LABEL_TOP_STYLE)); Cell paidByCell1 = row35.createCell(3); paidByCell1.setCellValue(LABEL_PAID_BY_BULGARIAN); paidByCell1.setCellStyle(styles.get(LABEL_TOP_STYLE)); Cell SenderCell1 = row35.createCell(5); SenderCell1.setCellValue(LABEL_SENDER_17_BULGARIAN); SenderCell1.setCellStyle(styles.get(LABEL_TOP_STYLE)); row35.createCell(6).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); Cell ReceiverCell1 = row35.createCell(7); ReceiverCell1.setCellValue(LABEL_RECEIVER_17_BULGARIAN); ReceiverCell1.setCellStyle(styles.get(LABEL_TOP_STYLE)); row35.createCell(8).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); currentRow++; Row row36 = sheet.getRow(currentRow); Cell agreementsLabelCell2 = row36.createCell(1); agreementsLabelCell2.setCellValue(LABEL_AGREEMENTS_ENGLISH); agreementsLabelCell2.setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); Cell paidByCell2 = row36.createCell(3); paidByCell2.setCellValue(LABEL_PAID_BY_ENGLISH); paidByCell2.setCellStyle(styles.get(LABEL_BOTTOM_STYLE)); row36.createCell(4).setCellStyle(styles.get(LABEL_BOTTOM_STYLE)); Cell SenderCell2 = row36.createCell(5); SenderCell2.setCellValue(LABEL_SENDER_17_ENGLISH); SenderCell2.setCellStyle(styles.get(LABEL_BOTTOM_STYLE)); row36.createCell(6).setCellStyle(styles.get(LABEL_BOTTOM_STYLE)); Cell ReceiverCell2 = row36.createCell(7); ReceiverCell2.setCellValue(LABEL_RECEIVER_17_ENGLISH); ReceiverCell2.setCellStyle(styles.get(LABEL_BOTTOM_STYLE)); row36.createCell(8).setCellStyle(styles.get(LABEL_BOTTOM_STYLE)); currentRow++; Row row37 = sheet.getRow(currentRow); currentRow++; Row row38 = sheet.getRow(currentRow); currentRow++; Row row39 = sheet.getRow(currentRow); currentRow++; Row row40 = sheet.getRow(currentRow); currentRow++; Row row41 = sheet.getRow(currentRow); for (int i = 1; i < 9; i++) { row37.createCell(i).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); row38.createCell(i).setCellStyle(styles.get(LABEL_BOTTOM_STYLE)); row39.createCell(i).setCellStyle(styles.get(LABEL_BOTTOM_STYLE)); row40.createCell(i).setCellStyle(styles.get(LABEL_BOTTOM_STYLE)); row41.createCell(i).setCellStyle(styles.get(LABEL_BOTTOM_STYLE)); } Cell carriageChargesCell1 = row37.getCell(3); carriageChargesCell1.setCellValue(LABEL_CARRIAGE_CHARGES_BULGARIAN); Cell carriageChargesCell2 = row38.getCell(3); carriageChargesCell2.setCellValue(LABEL_CARRIAGE_CHANGES_ENGLISH); Cell supplementaryChargesCell = row39.getCell(3); row39.setHeightInPoints(80); supplementaryChargesCell.setCellValue(LABEL_SUPPLEMENTARY_CHARGES); Cell customsDutiesCell = row40.getCell(3); row40.setHeightInPoints(50); customsDutiesCell.setCellValue(LABEL_CUSTOMS_DUTIES); Cell otherChargesCell = row41.getCell(3); row41.setHeightInPoints(50); otherChargesCell.setCellValue(LABEL_OTHER_CHARGES); currentRow++; for (int i = currentRow; i < currentRow + 2; i++) { sheet.createRow(i); mergeString = String.format("$B$%s:$C$%s", i + 1, i + 1); sheet.addMergedRegion(CellRangeAddress.valueOf(mergeString)); mergeString = String.format("$D$%s:$I$%s", i + 1, i + 1); sheet.addMergedRegion(CellRangeAddress.valueOf(mergeString)); } Row row42 = sheet.getRow(currentRow); currentRow++; Row row43 = sheet.getRow(currentRow); for (int i = 1; i < 9; i++) { row42.createCell(i).setCellStyle(styles.get(LABEL_TOP_STYLE)); row43.createCell(i).setCellStyle(styles.get(LABEL_BOTTOM_STYLE)); } Cell remarksCell1 = row42.getCell(1); remarksCell1.setCellValue(LABEL_REMARKS_BULGARIAN); Cell cashOnDeliveryCell1 = row42.getCell(3); cashOnDeliveryCell1.setCellValue(LABEL_CASH_ON_DELIVERY_BULGARIAN); Cell remarksCell2 = row43.getCell(1); remarksCell2.setCellValue(LABEL_REMARKS_ENGLISH); Cell cashOnDeliveryCell2 = row43.getCell(3); cashOnDeliveryCell2.setCellValue(LABEL_CASH_ON_DELIVERY_ENGLISH); return currentRow; }