List of usage examples for org.apache.poi.ss.usermodel Row setHeightInPoints
void setHeightInPoints(float height);
From source file:com.griffinslogistics.document.excel.BDLGenerator.java
private static void insertTableHeaders(Sheet sheet, CellStyle headerRowLeftCellStyleStyle, CellStyle headerRowMiddleCellStyle, CellStyle headerRowRightCellStyle) { Row tableHeadersRow = sheet.createRow(18); tableHeadersRow.setHeightInPoints((short) 35); sheet.addMergedRegion(CellRangeAddress.valueOf("$B$19:$E$19")); Cell titleCell = tableHeadersRow.createCell(1); titleCell.setCellValue("Titre"); titleCell.setCellStyle(headerRowLeftCellStyleStyle); for (int i = 2; i <= 4; i++) { tableHeadersRow.createCell(i).setCellStyle(headerRowMiddleCellStyle); }//from w ww . ja v a 2 s . c om Cell quantityCell = tableHeadersRow.createCell(5); quantityCell.setCellValue("Qunatite/carton"); quantityCell.setCellStyle(headerRowMiddleCellStyle); Cell boxesCountCell = tableHeadersRow.createCell(6); boxesCountCell.setCellValue("Nbre cartons"); boxesCountCell.setCellStyle(headerRowMiddleCellStyle); Cell totalQuantityCell = tableHeadersRow.createCell(7); totalQuantityCell.setCellValue("Quantite totale"); totalQuantityCell.setCellStyle(headerRowMiddleCellStyle); Cell palettesCountCell = tableHeadersRow.createCell(8); palettesCountCell.setCellValue("Nbre Palettes"); palettesCountCell.setCellStyle(headerRowRightCellStyle); }
From source file:com.griffinslogistics.document.excel.CMRGenerator.java
private static int generatePoint15Till19(XSSFSheet sheet, Map<String, CellStyle> styles, int currentRow) { currentRow++;/*from ww w .ja v a 2s . 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; }
From source file:com.griffinslogistics.document.excel.CMRGenerator.java
private static int generatePoint20Till24(XSSFSheet sheet, Map<String, CellStyle> styles, int currentRow, Pulsiodetails pulsiodetails) {//from w w w . ja v a 2 s . c o m currentRow++; String mergeString; for (int i = currentRow; i < currentRow + 2; i++) { Row row = sheet.createRow(i); mergeString = String.format("$B$%s:$I$%s", i + 1, i + 1); sheet.addMergedRegion(CellRangeAddress.valueOf(mergeString)); for (int j = 1; j < 9; j++) { row.createCell(j) .setCellStyle(styles.get(i == currentRow ? LABEL_MIDDLE_STYLE : LABEL_BOTTOM_STYLE)); } } for (int i = currentRow + 2; i < currentRow + 16; i++) { Row row = sheet.createRow(i); mergeString = String.format("$D$%s:$I$%s", i + 1, i + 1); sheet.addMergedRegion(CellRangeAddress.valueOf(mergeString)); for (int j = 1; j < 9; j++) { row.createCell(j).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); } } currentRow++; Row row45 = sheet.getRow(currentRow); row45.setHeightInPoints(30); row45.getCell(1).setCellValue(LABEL_POINT_20); currentRow++; Row row46 = sheet.getRow(currentRow); Cell establishedInCell = row46.getCell(1); establishedInCell.setCellValue(LABEL_ESTABLISHED_IN); Cell establishedOnCell = row46.getCell(2); establishedOnCell.setCellValue(LABEL_ESTABLISHED_ON); Cell goodsDeliveredCell = row46.getCell(3); goodsDeliveredCell.setCellValue(LABEL_GOODS_RECEIVED); currentRow++; Row row47 = sheet.getRow(currentRow); row47.getCell(3).setCellValue(LABEL_TIME_OF_ARRIVAL); currentRow++; Row row48 = sheet.getRow(currentRow); Cell cityCell = row48.getCell(1); cityCell.setCellStyle(styles.get(CONTENT_MIDDLE_STYLE)); cityCell.setCellValue("Sofia, Bulgaria"); Cell dateCell = row48.getCell(2); dateCell.setCellStyle(styles.get(CONTENT_MIDDLE_STYLE)); dateCell.setCellValue(new SimpleDateFormat("dd.MM.yyyy").format(new Date())); currentRow += 2; sheet.getRow(currentRow).getCell(3).setCellValue(LABEL_PLACE_20); currentRow++; Row row51 = sheet.getRow(currentRow); currentRow++; row51.getCell(1).setCellValue(TWENTY_TWO); row51.getCell(2).setCellValue(TWENTY_THREE); // Insert signature picture Workbook workbook = sheet.getWorkbook(); byte[] imageBytes = pulsiodetails.getSignature(); int pictureIdx = workbook.addPicture(imageBytes, Workbook.PICTURE_TYPE_PNG); CreationHelper helper = workbook.getCreationHelper(); Drawing drawing = sheet.createDrawingPatriarch(); ClientAnchor anchor = helper.createClientAnchor(); //set top-left corner for the image anchor.setCol1(1); anchor.setRow1(currentRow); XSSFPicture pict = (XSSFPicture) drawing.createPicture(anchor, pictureIdx); pict.resize(1.01, 5); currentRow += 4; Row row56 = sheet.getRow(currentRow); row56.getCell(3).setCellValue(LABEL_SIGNATURE_STAMP); currentRow += 2; Row row58 = sheet.getRow(currentRow); Cell signatureLabelCell1 = row58.getCell(1); signatureLabelCell1.setCellValue(LABEL_SENDER_SIGNATURE_BULGARIAN); Cell carrierSignatureCell = row58.getCell(2); carrierSignatureCell.setCellValue(LABEL_CARRIER_SIGNATURE_BULGARIAN); Cell receiverSignatureCell = row58.getCell(3); receiverSignatureCell.setCellValue(LABEL_RECEIVER_SIGNATURE_BULGARIAN); currentRow++; Row row59 = sheet.getRow(currentRow); Cell signatureLabelCell2 = row59.getCell(1); signatureLabelCell2.setCellValue(LABEL_SENDER_SIGNATURE_ENGLISH); Cell carrierSignatureCel2 = row59.getCell(2); carrierSignatureCel2.setCellValue(LABEL_CARRIER_SIGNATURE_BULGARIAN); Cell receiverSignatureCel2 = row59.getCell(3); receiverSignatureCel2.setCellValue(LABEL_RECEIVER_SIGNATURE_ENGLISH); currentRow++; Row row60 = sheet.createRow(currentRow); mergeString = String.format("$B$%s:$I$%s", currentRow + 1, currentRow + 1); sheet.addMergedRegion(CellRangeAddress.valueOf(mergeString)); for (int i = 1; i < 9; i++) { row60.createCell(i).setCellStyle(styles.get(LABEL_WHOLE_STYLE)); } Cell additionalSpaceCell = row60.getCell(1); additionalSpaceCell.setCellValue(LABEL_ADDITIONAL_SPACE); return currentRow; }
From source file:com.griffinslogistics.excel.BDLGenerator.java
private static void insertPulsioImage(Workbook workbook, Sheet sheet, Pulsiodetails pulsiodetails) { Row imageRow = sheet.createRow(0); imageRow.setHeightInPoints(55); byte[] imageBytes = pulsiodetails.getLogo(); int pictureIdx = workbook.addPicture(imageBytes, Workbook.PICTURE_TYPE_JPEG); CreationHelper helper = workbook.getCreationHelper(); Drawing drawing = sheet.createDrawingPatriarch(); ClientAnchor anchor = helper.createClientAnchor(); //set top-left corner for the image anchor.setCol1(8);//from ww w .j a v a 2 s.c o m anchor.setRow1(0); Picture pict = drawing.createPicture(anchor, pictureIdx); pict.resize(); }
From source file:com.griffinslogistics.excel.BookLabelGenerator.java
public static void generateLabel(OutputStream outputStream, BookLabelModel bookLabelModel) { try {/* w ww . jav a2 s . c om*/ XSSFWorkbook workbook = new XSSFWorkbook(); Map<String, CellStyle> styles = createStyles(workbook); String title = bookLabelModel.getTitle().replace("/", "-"); bookLabelModel.setTitle(title); Sheet sheet = workbook.createSheet(bookLabelModel.getBookNumber() + " " + bookLabelModel.getTitle()); for (int i = 0; i < 20; i++) { Row row = sheet.createRow(i); if (i != 0 && i != 10) { row.setHeightInPoints(25); } else { row.setHeightInPoints(12); } } //column widths sheet.setColumnWidth(0, 5000); sheet.setColumnWidth(1, 10000); sheet.setColumnWidth(3, 5000); sheet.setColumnWidth(4, 10000); generateHeaders(sheet, styles); generateAddress(sheet, styles, bookLabelModel); generateClient(sheet, styles, bookLabelModel); generateTransportation(sheet, styles, bookLabelModel); generateTitle(sheet, styles, bookLabelModel); generateCountPerBox(sheet, styles, bookLabelModel); generateCountPerAddress(sheet, styles, bookLabelModel); sheet.autoSizeColumn(1); sheet.autoSizeColumn(4); workbook.write(outputStream); } catch (IOException ex) { Logger.getLogger(BookLabelGenerator.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.griffinslogistics.excel.BookLabelGenerator.java
private static void generateAddress(Sheet sheet, Map<String, CellStyle> styles, BookLabelModel bookLabelModel) { sheet.addMergedRegion(CellRangeAddress.valueOf("$A2:A3")); sheet.addMergedRegion(CellRangeAddress.valueOf("$A12:A13")); sheet.addMergedRegion(CellRangeAddress.valueOf("$D2:D3")); sheet.addMergedRegion(CellRangeAddress.valueOf("$D12:D13")); Row row2 = sheet.getRow(1); row2.setHeightInPoints(25); Row row3 = sheet.getRow(2);/*from www . jav a 2 s .c om*/ row3.setHeightInPoints(25); Cell a2 = row2.createCell(0); a2.setCellValue(ADDRESS); a2.setCellStyle(styles.get(STYLE_LABEL)); Cell a3 = row3.createCell(0); a3.setCellStyle(styles.get(STYLE_LABEL)); Cell d2 = row2.createCell(3); d2.setCellValue(ADDRESS); d2.setCellStyle(styles.get(STYLE_LABEL)); Cell d3 = row3.createCell(3); d3.setCellStyle(styles.get(STYLE_LABEL)); Cell b2 = row2.createCell(1); b2.setCellValue(bookLabelModel.getAddress()); b2.setCellStyle(styles.get(STYLE_CONTENT)); Cell b3 = row3.createCell(1); b3.setCellValue(bookLabelModel.getPostalCode()); b3.setCellStyle(styles.get(STYLE_CONTENT)); Cell e2 = row2.createCell(4); e2.setCellValue(bookLabelModel.getAddress()); e2.setCellStyle(styles.get(STYLE_CONTENT)); Cell e3 = row3.createCell(4); e3.setCellValue(bookLabelModel.getPostalCode()); e3.setCellStyle(styles.get(STYLE_CONTENT)); Row row12 = sheet.getRow(11); row12.setHeightInPoints(25); Row row13 = sheet.getRow(12); row13.setHeightInPoints(25); Cell a12 = row12.createCell(0); a12.setCellValue(ADDRESS); a12.setCellStyle(styles.get(STYLE_LABEL)); Cell a13 = row13.createCell(0); a13.setCellStyle(styles.get(STYLE_LABEL)); Cell d12 = row12.createCell(3); d12.setCellValue(ADDRESS); d12.setCellStyle(styles.get(STYLE_LABEL)); Cell d13 = row13.createCell(3); d13.setCellStyle(styles.get(STYLE_LABEL)); Cell b12 = row12.createCell(1); b12.setCellValue(bookLabelModel.getAddress()); b12.setCellStyle(styles.get(STYLE_CONTENT)); Cell b13 = row13.createCell(1); b13.setCellValue(bookLabelModel.getPostalCode()); b13.setCellStyle(styles.get(STYLE_CONTENT)); Cell e12 = row12.createCell(4); e12.setCellValue(bookLabelModel.getAddress()); e12.setCellStyle(styles.get(STYLE_CONTENT)); Cell e13 = row13.createCell(4); e13.setCellValue(bookLabelModel.getPostalCode()); e13.setCellStyle(styles.get(STYLE_CONTENT)); }
From source file:com.griffinslogistics.excel.CMRGenerator.java
private static int generatePoint20Till24(XSSFSheet sheet, Map<String, CellStyle> styles, int currentRow, Pulsiodetails pulsiodetails) {/* ww w . j a v a2 s . com*/ currentRow++; String mergeString; for (int i = currentRow; i < currentRow + 2; i++) { Row row = sheet.createRow(i); mergeString = String.format("$B$%s:$I$%s", i + 1, i + 1); sheet.addMergedRegion(CellRangeAddress.valueOf(mergeString)); for (int j = 1; j < 9; j++) { row.createCell(j) .setCellStyle(styles.get(i == currentRow ? LABEL_MIDDLE_STYLE : LABEL_BOTTOM_STYLE)); } } for (int i = currentRow + 2; i < currentRow + 16; i++) { Row row = sheet.createRow(i); mergeString = String.format("$D$%s:$I$%s", i + 1, i + 1); sheet.addMergedRegion(CellRangeAddress.valueOf(mergeString)); for (int j = 1; j < 9; j++) { row.createCell(j).setCellStyle(styles.get(LABEL_MIDDLE_STYLE)); } } currentRow++; Row row45 = sheet.getRow(currentRow); row45.setHeightInPoints(30); row45.getCell(1).setCellValue(LABEL_POINT_20); currentRow++; Row row46 = sheet.getRow(currentRow); Cell establishedInCell = row46.getCell(1); establishedInCell.setCellValue(LABEL_ESTABLISHED_IN); Cell establishedOnCell = row46.getCell(2); establishedOnCell.setCellValue(LABEL_ESTABLISHED_ON); Cell goodsDeliveredCell = row46.getCell(3); goodsDeliveredCell.setCellValue(LABEL_GOODS_RECEIVED); currentRow++; Row row47 = sheet.getRow(currentRow); row47.getCell(3).setCellValue(LABEL_TIME_OF_ARRIVAL); currentRow++; Row row48 = sheet.getRow(currentRow); Cell cityCell = row48.getCell(1); cityCell.setCellStyle(styles.get(CONTENT_MIDDLE_STYLE)); cityCell.setCellValue("Sofia, Bulgaria"); Cell dateCell = row48.getCell(2); dateCell.setCellStyle(styles.get(CONTENT_MIDDLE_STYLE)); dateCell.setCellValue(new SimpleDateFormat("dd.MM.yyyy").format(new Date())); currentRow += 2; sheet.getRow(currentRow).getCell(3).setCellValue(LABEL_PLACE_20); currentRow++; Row row51 = sheet.getRow(currentRow); currentRow++; row51.getCell(1).setCellValue(TWENTY_TWO); row51.getCell(2).setCellValue(TWENTY_THREE); // Insert signature picture Workbook workbook = sheet.getWorkbook(); byte[] imageBytes = pulsiodetails.getSignature(); int pictureIdx = workbook.addPicture(imageBytes, Workbook.PICTURE_TYPE_JPEG); CreationHelper helper = workbook.getCreationHelper(); Drawing drawing = sheet.createDrawingPatriarch(); ClientAnchor anchor = helper.createClientAnchor(); //set top-left corner for the image anchor.setCol1(1); anchor.setRow1(currentRow); Picture pict = drawing.createPicture(anchor, pictureIdx); pict.resize(); currentRow += 4; Row row56 = sheet.getRow(currentRow); row56.getCell(3).setCellValue(LABEL_SIGNATURE_STAMP); currentRow += 2; Row row58 = sheet.getRow(currentRow); Cell signatureLabelCell1 = row58.getCell(1); signatureLabelCell1.setCellValue(LABEL_SENDER_SIGNATURE_BULGARIAN); Cell carrierSignatureCell = row58.getCell(2); carrierSignatureCell.setCellValue(LABEL_CARRIER_SIGNATURE_BULGARIAN); Cell receiverSignatureCell = row58.getCell(3); receiverSignatureCell.setCellValue(LABEL_RECEIVER_SIGNATURE_BULGARIAN); currentRow++; Row row59 = sheet.getRow(currentRow); Cell signatureLabelCell2 = row59.getCell(1); signatureLabelCell2.setCellValue(LABEL_SENDER_SIGNATURE_ENGLISH); Cell carrierSignatureCel2 = row59.getCell(2); carrierSignatureCel2.setCellValue(LABEL_CARRIER_SIGNATURE_BULGARIAN); Cell receiverSignatureCel2 = row59.getCell(3); receiverSignatureCel2.setCellValue(LABEL_RECEIVER_SIGNATURE_ENGLISH); currentRow++; Row row60 = sheet.createRow(currentRow); mergeString = String.format("$B$%s:$I$%s", currentRow + 1, currentRow + 1); sheet.addMergedRegion(CellRangeAddress.valueOf(mergeString)); for (int i = 1; i < 9; i++) { row60.createCell(i).setCellStyle(styles.get(LABEL_WHOLE_STYLE)); } Cell additionalSpaceCell = row60.getCell(1); additionalSpaceCell.setCellValue(LABEL_ADDITIONAL_SPACE); return currentRow; }
From source file:com.heimaide.server.common.utils.excel.ExportExcel.java
License:Open Source License
private void initialize(String title, List<String> headerList) { this.wb = new SXSSFWorkbook(500); this.sheet = wb.createSheet("Export"); this.styles = createStyles(wb); // Create title if (StringUtils.isNotBlank(title)) { Row titleRow = sheet.createRow(rownum++); titleRow.setHeightInPoints(30); Cell titleCell = titleRow.createCell(0); titleCell.setCellStyle(styles.get("title")); titleCell.setCellValue(title);//from w w w.jav a2 s . c o m sheet.addMergedRegion(new CellRangeAddress(titleRow.getRowNum(), titleRow.getRowNum(), titleRow.getRowNum(), headerList.size() - 1)); } // Create header if (headerList == null) { throw new RuntimeException("headerList not null!"); } Row headerRow = sheet.createRow(rownum++); headerRow.setHeightInPoints(16); for (int i = 0; i < headerList.size(); i++) { Cell cell = headerRow.createCell(i); cell.setCellStyle(styles.get("header")); String[] ss = StringUtils.split(headerList.get(i), "**", 2); if (ss.length == 2) { cell.setCellValue(ss[0]); Comment comment = this.sheet.createDrawingPatriarch() .createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 3, 3, (short) 5, 6)); comment.setString(new XSSFRichTextString(ss[1])); cell.setCellComment(comment); } else { cell.setCellValue(headerList.get(i)); } sheet.autoSizeColumn(i); } for (int i = 0; i < headerList.size(); i++) { int colWidth = sheet.getColumnWidth(i) * 2; sheet.setColumnWidth(i, colWidth < 3000 ? 3000 : colWidth); } log.debug("Initialize success."); }
From source file:com.ideaspymes.proyecttemplate.stock.web.ProductoConsultaBean.java
@Override public Workbook getWorkBook() { Workbook wb = new XSSFWorkbook(); Sheet sheet = wb.createSheet("My Sample Excel"); List<CatalogoProductos> lista = (List<CatalogoProductos>) getDetalles(); sheet.setDefaultRowHeight((short) (sheet.getDefaultRowHeight() * new Short("6"))); org.apache.poi.ss.usermodel.Font fontTitulo = wb.createFont(); fontTitulo.setFontHeightInPoints((short) 12); fontTitulo.setBoldweight(org.apache.poi.ss.usermodel.Font.BOLDWEIGHT_BOLD); org.apache.poi.ss.usermodel.Font fontTituloPricipal = wb.createFont(); fontTituloPricipal.setFontHeightInPoints((short) 22); fontTituloPricipal.setBoldweight(org.apache.poi.ss.usermodel.Font.BOLDWEIGHT_BOLD); DataFormat format = wb.createDataFormat(); CellStyle styleTituloPrincipal = wb.createCellStyle(); styleTituloPrincipal.setFont(fontTituloPricipal); styleTituloPrincipal.setVerticalAlignment(CellStyle.VERTICAL_CENTER); styleTituloPrincipal.setAlignment(CellStyle.ALIGN_CENTER); CellStyle styleTitulo = wb.createCellStyle(); styleTitulo.setFont(fontTitulo);/* w w w.j a v a 2s .c o m*/ styleTitulo.setVerticalAlignment(CellStyle.VERTICAL_CENTER); styleTitulo.setFillForegroundColor(IndexedColors.BLUE_GREY.getIndex()); styleTitulo.setFillPattern(CellStyle.SOLID_FOREGROUND); styleTitulo.setWrapText(true); CellStyle styleNumero = wb.createCellStyle(); styleNumero.setDataFormat(format.getFormat("#,##0")); styleNumero.setWrapText(true); styleNumero.setVerticalAlignment(CellStyle.VERTICAL_CENTER); styleNumero.setAlignment(CellStyle.ALIGN_CENTER); CellStyle styleFecha = wb.createCellStyle(); styleFecha.setDataFormat(format.getFormat("dd/MM/yyyy")); styleFecha.setVerticalAlignment(CellStyle.VERTICAL_CENTER); styleFecha.setAlignment(CellStyle.ALIGN_CENTER); CellStyle style = wb.createCellStyle(); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setWrapText(true); CellStyle styleCenter = wb.createCellStyle(); styleCenter.setVerticalAlignment(CellStyle.VERTICAL_CENTER); styleCenter.setAlignment(CellStyle.ALIGN_CENTER); styleCenter.setWrapText(true); Row rowTitle = sheet.createRow(0); Cell cellTitle = rowTitle.createCell(1); cellTitle.setCellStyle(styleTituloPrincipal); sheet.addMergedRegion(new CellRangeAddress(0, //first row (0-based) 1, //last row (0-based) 1, //first column (0-based) 11 //last column (0-based) )); cellTitle.setCellValue("Listado de Activos"); int i = 2; Row row0 = sheet.createRow(i); row0.setHeight((short) 500); Cell cell1 = row0.createCell(1); cell1.setCellValue("Foto"); cell1.setCellStyle(styleTitulo); Cell cellFecha = row0.createCell(3); cellFecha.setCellValue("Fecha Ingreso"); cellFecha.setCellStyle(styleTitulo); Cell cellFechaCarga = row0.createCell(4); cellFechaCarga.setCellValue("Fecha Carga"); cellFechaCarga.setCellStyle(styleTitulo); Cell cell3 = row0.createCell(5); cell3.setCellValue("Nombre"); cell3.setCellStyle(styleTitulo); Cell cell4 = row0.createCell(6); cell4.setCellValue("Cdigo"); cell4.setCellStyle(styleTitulo); Cell cell5 = row0.createCell(7); cell5.setCellValue("Descripcin"); cell5.setCellStyle(styleTitulo); Cell cell6 = row0.createCell(8); cell6.setCellValue("Es Regalo?"); cell6.setCellStyle(styleTitulo); Cell cell7 = row0.createCell(9); cell7.setCellValue("Familia"); cell7.setCellStyle(styleTitulo); Cell cell8 = row0.createCell(10); cell8.setCellValue("Ubicaciones"); cell8.setCellStyle(styleTitulo); Cell cell9 = row0.createCell(11); cell9.setCellValue("Stock"); cell9.setCellStyle(styleTitulo); for (CatalogoProductos cp : lista) { int indexFila = i + 1; if (cp.getImagen() != null) { int pictureIdx = wb.addPicture(cp.getImagen(), Workbook.PICTURE_TYPE_PNG); CreationHelper helper = wb.getCreationHelper(); //Creates the top-level drawing patriarch. Drawing drawing = sheet.createDrawingPatriarch(); //Create an anchor that is attached to the worksheet ClientAnchor anchor = helper.createClientAnchor(); //set top-left corner for the image anchor.setCol1(1); anchor.setRow1(indexFila); //Creates a picture Picture pict = drawing.createPicture(anchor, pictureIdx); //Reset the image to the original size pict.resize(0.4); } Row row1 = sheet.createRow(indexFila); row1.setHeightInPoints(80f); Cell cellColFecha = row1.createCell(3); if (cp.getFecha() != null) { cellColFecha.setCellValue(cp.getFecha()); cellColFecha.setCellStyle(styleFecha); } else { cellColFecha.setCellValue(""); cellColFecha.setCellStyle(styleFecha); } Cell cellColFechaCarga = row1.createCell(4); if (cp.getFechaCarga() != null) { cellColFechaCarga.setCellValue(cp.getFechaCarga()); cellColFechaCarga.setCellStyle(styleFecha); } else { cellColFechaCarga.setCellValue(""); cellColFechaCarga.setCellStyle(styleFecha); } Cell cellCol1 = row1.createCell(5); cellCol1.setCellValue(cp.getProducto()); cellCol1.setCellStyle(style); Cell cellCol2 = row1.createCell(6); cellCol2.setCellValue(cp.getCodigo()); cellCol2.setCellStyle(styleNumero); Cell cellCol3 = row1.createCell(7); cellCol3.setCellValue(cp.getDescripcion()); cellCol3.setCellStyle(style); Cell cellCol4 = row1.createCell(8); cellCol4.setCellValue(cp.isEsRegalo() ? "SI" : "NO"); cellCol4.setCellStyle(styleCenter); Cell cellCol5 = row1.createCell(9); cellCol5.setCellValue(cp.getFamilia()); cellCol5.setCellStyle(style); Cell cellCol6 = row1.createCell(10); cellCol6.setCellValue(cp.getUbicaciones()); cellCol6.setCellStyle(style); Cell cellCol7 = row1.createCell(11); cellCol7.setCellValue(cp.getStock()); cellCol7.setCellStyle(styleNumero); i++; } sheet.setColumnWidth(1, 4000); sheet.setColumnWidth(2, 0); sheet.setColumnWidth(3, 4000); sheet.setColumnWidth(4, 4000); sheet.setColumnWidth(5, 10000); sheet.setColumnWidth(6, 3000); sheet.setColumnWidth(7, 10000); sheet.setColumnWidth(8, 3500); sheet.setColumnWidth(9, 6000); sheet.setColumnWidth(10, 10000); sheet.setColumnWidth(11, 2000); return wb; }
From source file:com.inet.web.service.mail.utils.ExportUtils.java
License:Open Source License
/** * /*from www . j a v a2s . c o m*/ * @param key * @return * @throws WebOSException */ public static byte[] exportErrorAccount(String key) throws WebOSException { AccountImport accountImport = AccountImportCacheService.get(key); if (accountImport == null) { return null; } try { ByteArrayOutputStream output = new ByteArrayOutputStream(); Workbook workbook = new HSSFWorkbook(); Sheet sheet = workbook.createSheet("Email list"); PrintSetup printSetup = sheet.getPrintSetup(); printSetup.setLandscape(true); sheet.setFitToPage(true); sheet.setHorizontallyCenter(true); Row headerRow = sheet.createRow(0); headerRow.setHeightInPoints(30); headerRow.createCell(STT).setCellValue("STT"); headerRow.createCell(FULL_NAME).setCellValue("FULL NAME"); headerRow.createCell(USER).setCellValue("USER"); headerRow.createCell(LAST_NAME).setCellValue("LAST NAME"); headerRow.createCell(MIDDLE_NAME).setCellValue("MIDDLE NAME"); headerRow.createCell(FIRST_NAME).setCellValue("FIRST NAME"); headerRow.createCell(STATUS).setCellValue("STATUS"); headerRow.createCell(DUPLICATE).setCellValue("DUPLICATE"); for (int i = 0; i < accountImport.getError().size(); i++) { AccountImportInfo account = accountImport.getError().get(i); Row row = sheet.createRow(i + 1); row.setHeightInPoints(40); row.createCell(STT).setCellValue(account.getNumber()); row.createCell(FULL_NAME).setCellValue(account.getFullName()); row.createCell(USER).setCellValue(account.getAccount()); row.createCell(LAST_NAME).setCellValue(account.getLastName()); row.createCell(MIDDLE_NAME).setCellValue(account.getMiddleName()); row.createCell(FIRST_NAME).setCellValue(account.getFirstName()); row.createCell(STATUS).setCellValue(getStatus(account.getStatus())); row.createCell(DUPLICATE).setCellValue(account.getExistAccount()); } workbook.write(output); output.close(); return output.toByteArray(); } catch (Exception e) { e.printStackTrace(); throw new WebOSException(e.getMessage(), e); } }