List of usage examples for org.apache.poi.ss.usermodel Workbook PICTURE_TYPE_PNG
int PICTURE_TYPE_PNG
To view the source code for org.apache.poi.ss.usermodel Workbook PICTURE_TYPE_PNG.
Click Source Link
From source file:cn.afterturn.easypoi.excel.export.base.BaseExportService.java
License:Apache License
/** * ?,?/*from w w w .j a v a2 s. c om*/ * * @author JueYue 20131125 */ public int getImageType(byte[] value) { String type = PoiPublicUtil.getFileExtendName(value); if ("JPG".equalsIgnoreCase(type)) { return Workbook.PICTURE_TYPE_JPEG; } else if ("PNG".equalsIgnoreCase(type)) { return Workbook.PICTURE_TYPE_PNG; } return Workbook.PICTURE_TYPE_JPEG; }
From source file:cn.bzvs.excel.export.base.ExcelExportBase.java
License:Apache License
/** * ?,?//from ww w.j av a2s . c om * * @param value * @return */ public int getImageType(byte[] value) { String type = PoiPublicUtil.getFileExtendName(value); if (type.equalsIgnoreCase("JPG")) { return Workbook.PICTURE_TYPE_JPEG; } else if (type.equalsIgnoreCase("PNG")) { return Workbook.PICTURE_TYPE_PNG; } return Workbook.PICTURE_TYPE_JPEG; }
From source file:com.actelion.research.spiritapp.report.StudyDesignReport.java
License:Open Source License
@Override protected void populateWorkBook() throws Exception { CreationHelper helper = wb.getCreationHelper(); //create sheet Sheet sheet = createSheet(wb, "Study Design"); sheet.setPrintGridlines(false);/*from w w w.j av a 2s. c o m*/ createHeadersWithTitle(sheet, study, "Study Design"); // Create the drawing patriarch. This is the top level container for all shapes. Drawing drawing = sheet.createDrawingPatriarch(); ByteArrayOutputStream os = new ByteArrayOutputStream(); //10.5inches*600 = 6300 pixels, 7.5*600=4500 pixels, on 600dpi int size = FastFont.getDefaultFontSize(); FastFont.setDefaultFontSize(36); BufferedImage img = StudyDepictor.getImage(study, 6300, 4500, 1); ImageIO.write(img, "PNG", os); FastFont.setDefaultFontSize(size); //add a picture shape int pictureIdx = wb.addPicture(os.toByteArray(), Workbook.PICTURE_TYPE_PNG); ClientAnchor anchor = helper.createClientAnchor(); anchor.setAnchorType(ClientAnchor.MOVE_DONT_RESIZE); anchor.setCol1(0); anchor.setRow1(3); Picture pict = drawing.createPicture(anchor, pictureIdx); final double scaleDown = .33; //Samplings int y = (int) (img.getHeight() * scaleDown) / 20 + 5; int nSamplings = 0; for (NamedSampling ns : study.getNamedSamplings()) { nSamplings = Math.max(nSamplings, ns.getAllSamplings().size()); } if (study.getNamedSamplings().size() > 0) { set(sheet, y++, 0, "Sampling Templates", Style.S_TITLE14BLUE); int count = 0; for (NamedSampling ns : study.getNamedSamplings()) { set(sheet, y, count, ns.getName(), Style.S_TH_LEFT); int line = 0; for (Sampling s : ns.getAllSamplings()) { set(sheet, y + (++line), count, MiscUtils.removeHtml(s.getDetailsWithMeasurements()), Style.S_TD_LEFT); } while (line < nSamplings) { set(sheet, y + (++line), count, "", Style.S_TD_LEFT); } count++; } } //Treatments y += nSamplings + 3; if (study.getNamedTreatments().size() > 0) { set(sheet, y++, 0, "Treatments", Style.S_TITLE14BLUE); int count = 0; for (NamedTreatment nt : study.getNamedTreatments()) { set(sheet, y, count, nt.getName(), Style.S_TH_LEFT); set(sheet, y + 1, count, nt.getCompoundAndUnit1(), Style.S_TD_LEFT); set(sheet, y + 2, count, nt.getCompoundAndUnit2(), Style.S_TD_LEFT); count++; } } POIUtils.autoSizeColumns(sheet, -1, true); pict.resize(); pict.resize(scaleDown); }
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.j av a 2s. co 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.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 a2s.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.respam.comniq.models.POIexcelExporter.java
License:Open Source License
public void excelWriter(JSONObject parsedObj, int rownum) throws IOException { String path = System.getProperty("user.home") + File.separator + "comniq" + File.separator + "output"; File file = new File(path + File.separator + "POImovieInfo.xlsx"); String thumbnailPath = System.getProperty("user.home") + File.separator + "comniq" + File.separator + "output" + File.separator + "thumbnails"; File posterFile = new File(thumbnailPath + File.separator + parsedObj.get("Title") + ".jpg"); if (!file.exists()) { createFile();/* ww w . jav a 2 s . c o m*/ } if (file.exists() && checked.equals(false)) { findLastRow(); } try { FileInputStream fis = new FileInputStream(file); XSSFWorkbook workbook = new XSSFWorkbook(fis); XSSFSheet sheet = workbook.getSheet("Movies"); Map<String, Object[]> label = new TreeMap<>(); label.put("1", new Object[] { "", parsedObj.get("Title"), parsedObj.get("Released"), parsedObj.get("Metascore"), parsedObj.get("imdbRating"), parsedObj.get("Plot"), parsedObj.get("imdbID"), parsedObj.get("Genre"), parsedObj.get("Director"), parsedObj.get("Actors"), parsedObj.get("Rated"), parsedObj.get("Runtime") }); Set<String> keyset = label.keySet(); // Setting Style for the Label Row XSSFCellStyle contentStyle = workbook.createCellStyle(); contentStyle.setWrapText(true); contentStyle.setVerticalAlignment(VerticalAlignment.TOP); rownum = rownum + lastRow; if (posterFile.exists()) { InputStream imageStream = new FileInputStream( thumbnailPath + File.separator + parsedObj.get("Title") + ".jpg"); byte[] imageBytes = IOUtils.toByteArray(imageStream); pictureureIdx = workbook.addPicture(imageBytes, Workbook.PICTURE_TYPE_PNG); imageStream.close(); CreationHelper helper = workbook.getCreationHelper(); drawing = sheet.createDrawingPatriarch(); anchor = helper.createClientAnchor(); } for (String key : keyset) { Row row = sheet.createRow(rownum++); row.setHeight((short) 2000); Object[] objArr = label.get(key); int cellnum = 0; for (Object obj : objArr) { Cell cell = row.createCell(cellnum++); cell.setCellStyle(contentStyle); cell.setCellValue((String) obj); } if (posterFile.exists()) { anchor.setCol1(0); anchor.setRow1(rownum - 1); anchor.setCol2(0); anchor.setRow2(rownum - 1); Picture pict = drawing.createPicture(anchor, pictureureIdx); pict.resize(1, 1); } } FileOutputStream out = new FileOutputStream(file); workbook.write(out); out.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.upbest.utils.AddDimensionedImage.java
License:Apache License
/** * Add an image to a worksheet.//from www . j ava2 s .c o m * * @param colNumber A primitive int that contains the index number of a * column on the worksheet; POI column indices are zero * based. Together with the rowNumber parameter's value, * this parameter identifies a cell on the worksheet. The * images top left hand corner will be aligned with the * top left hand corner of this cell. * @param rowNumber A primitive int that contains the index number of a row * on the worksheet; POI row indices are zero based. * Together with the rowNumber parameter's value, this * parameter identifies a cell on the worksheet. The * images top left hand corner will be aligned with the * top left hand corner of this cell. * @param sheet A reference to the sheet that contains the cell identified * by the two parameters above. * @param drawing An instance of the DrawingPatriarch class. This is now * passed into the method where it was, previously, recovered * from the sheet in order to allow multiple pictures be * inserted. If the patriarch was not 'cached in this manner * each time it was created any previously positioned images * would be simply over-written. * @param imageFile An instance of the URL class that encapsulates the name * of and path to the image that is to be 'inserted into' * the sheet. * @param reqImageWidthMM A primitive double that contains the required * width of the image in millimetres. * @param reqImageHeightMM A primitive double that contains the required * height of the image in millimetres. * @param resizeBehaviour A primitive int whose value will determine how * the code should react if the image is larger than * the cell referenced by the colNumber and * rowNumber parameters. Four constants are provided * to determine what should happen; * AddDimensionedImage.EXPAND_ROW * AddDimensionedImage.EXPAND_COLUMN * AddDimensionedImage.EXPAND_ROW_AND_COLUMN * AddDimensionedImage.OVERLAY_ROW_AND_COLUMN * @throws java.io.FileNotFoundException If the file containing the image * cannot be located. * @throws java.io.IOException If a problem occurs whilst reading the file * of image data. * @throws java.lang.IllegalArgumentException If an invalid value is passed * to the resizeBehaviour * parameter or if the extension * of the image file indicates that * it is of a type that cannot * currently be added to the worksheet. */ public void addImageToSheet(int colNumber, int rowNumber, Sheet sheet, Drawing drawing, URL imageFile, double reqImageWidthMM, double reqImageHeightMM, int resizeBehaviour) throws IOException, IllegalArgumentException { ClientAnchor anchor = null; ClientAnchorDetail rowClientAnchorDetail = null; ClientAnchorDetail colClientAnchorDetail = null; int imageType = 0; // Validate the resizeBehaviour parameter. if ((resizeBehaviour != AddDimensionedImage.EXPAND_COLUMN) && (resizeBehaviour != AddDimensionedImage.EXPAND_ROW) && (resizeBehaviour != AddDimensionedImage.EXPAND_ROW_AND_COLUMN) && (resizeBehaviour != AddDimensionedImage.OVERLAY_ROW_AND_COLUMN)) { throw new IllegalArgumentException("Invalid value passed to the " + "resizeBehaviour parameter of AddDimensionedImage.addImageToSheet()"); } // Call methods to calculate how the image and sheet should be // manipulated to accomodate the image; columns and then rows. colClientAnchorDetail = this.fitImageToColumns(sheet, colNumber, reqImageWidthMM, resizeBehaviour); rowClientAnchorDetail = this.fitImageToRows(sheet, rowNumber, reqImageHeightMM, resizeBehaviour); // Having determined if and how to resize the rows, columns and/or the // image, create the ClientAnchor object to position the image on // the worksheet. Note how the two ClientAnchorDetail records are // interrogated to recover the row/column co-ordinates and any insets. // The first two parameters are not used currently but could be if the // need arose to extend the functionality of this code by adding the // ability to specify that a clear 'border' be placed around the image. anchor = sheet.getWorkbook().getCreationHelper().createClientAnchor(); anchor.setDx1(0); anchor.setDy1(0); anchor.setDx2(colClientAnchorDetail.getInset()); anchor.setDy2(rowClientAnchorDetail.getInset()); anchor.setCol1(colClientAnchorDetail.getFromIndex()); anchor.setRow1(rowClientAnchorDetail.getFromIndex()); anchor.setCol2(colClientAnchorDetail.getToIndex()); anchor.setRow2(rowClientAnchorDetail.getToIndex()); // For now, set the anchor type to do not move or resize the // image as the size of the row/column is adjusted. This could easilly // become another parameter passed to the method. Please read the note // above regarding the behaviour of image resizing. anchor.setAnchorType(ClientAnchor.MOVE_AND_RESIZE); // Now, add the picture to the workbook. Note that unlike the similar // method in the HSSF Examples section, the image type is checked. First, // the image files location is identified by interrogating the URL passed // to the method, the images type is identified before it is added to the // sheet. String sURL = imageFile.toString().toLowerCase(); if (sURL.endsWith(".png")) { imageType = Workbook.PICTURE_TYPE_PNG; } else if (sURL.endsWith("jpg") || sURL.endsWith(".jpeg")) { imageType = Workbook.PICTURE_TYPE_JPEG; } else { throw new IllegalArgumentException("Invalid Image file : " + sURL); } int index = sheet.getWorkbook().addPicture(IOUtils.toByteArray(imageFile.openStream()), imageType); drawing.createPicture(anchor, index); }
From source file:com.vodafone.poms.ii.helpers.ExportManager.java
public void exportActivity() { try {/*from w ww. j a va 2 s . c om*/ List<Activity> activities = activityController.getExportItems(fromDate, toDate); XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet("Master Track"); int imgPckId = addImageToWorkbook(workbook, "/home/poms/uploaded_data/pkg.png", Workbook.PICTURE_TYPE_PNG); String imgPckRelId = addImageToSheet(sheet, imgPckId, Workbook.PICTURE_TYPE_PNG); Row row = sheet.createRow(0); for (int i = 0; i < activityHeaders.length; i++) { row.createCell(i).setCellValue(activityHeaders[i]); } for (int i = 0; i < activities.size(); i++) { row = sheet.createRow(i + 1); row.createCell(0).setCellValue(activities.get(i).getSite().getSitePhysical()); row.createCell(1).setCellValue(activities.get(i).getAsp().getSubcontractorName()); row.createCell(2).setCellValue(activities.get(i).getArea().getAreaName()); row.createCell(3).setCellValue(activities.get(i).getVendorOwner().getOwnerName()); if (activities.get(i).getClaimStatus() != null) { row.createCell(4).setCellValue(activities.get(i).getClaimStatus().getClaimName()); } else { row.createCell(4).setCellValue(""); } if (activities.get(i).getApprovalStatus() != null) { row.createCell(5).setCellValue(activities.get(i).getApprovalStatus().getStatusName()); } else { row.createCell(5).setCellValue(""); } row.createCell(6).setCellValue(activities.get(i).getActivityType().getDomainName()); if (activities.get(i).getPhase() != null) { row.createCell(7).setCellValue(activities.get(i).getPhase().getPhaseName()); } else { row.createCell(7).setCellValue(""); } row.createCell(8).setCellValue(activities.get(i).getActivityDate()); row.createCell(9).setCellValue(activities.get(i).getAcMaterialId()); row.createCell(10).setCellValue(activities.get(i).getAcDescription()); row.createCell(11).setCellValue(activities.get(i).getActivityDetails()); row.createCell(12).setCellValue(activities.get(i).getQty()); row.createCell(13).setCellValue(activities.get(i).getAcVendorPrice()); row.createCell(14).setCellValue(activities.get(i).getTotalPriceVendor()); row.createCell(15).setCellValue(activities.get(i).getTotalPriceVendorTaxes()); row.createCell(16).setCellValue(activities.get(i).getAcSubcontractorPrice()); row.createCell(17).setCellValue(activities.get(i).getTotalPriceAsp()); row.createCell(18).setCellValue(activities.get(i).getTotalUm()); row.createCell(19).setCellValue(activities.get(i).getTotalUmPercent()); row.createCell(20).setCellValue(activities.get(i).getActivityComment()); row.createCell(21).setCellValue((activities.get(i).getAspPoCollection().isEmpty() ? "Uncorrelated" : ((AspPo) activities.get(i).getAspPoCollection().toArray()[0]).getPoNumber())); if (activities.get(i).getActivityAttachmentsCollection() != null) { if (activities.get(i).getActivityAttachmentsCollection().size() > 0) { Object[] attachments = activities.get(i).getActivityAttachmentsCollection().toArray(); for (int j = 0; j < attachments.length; j++) { XSSFClientAnchor imgAnchor1 = new XSSFClientAnchor(0, 0, 0, 0, (23 + j), row.getRowNum(), (23 + j + 1), row.getRowNum() + 1); String oleRelId1 = addFile(sheet, ((ActivityAttachments) attachments[j]).getAttachmentLocation(), (i + j + activities.get(i).getActivityId().intValue() + Math.random())); int shapeId1 = addImageToShape(sheet, imgAnchor1, imgPckId); addObjectToShape(sheet, imgAnchor1, shapeId1, oleRelId1, imgPckRelId, "Objekt-Manager-Shellobjekt"); } } } } FacesContext facesContext = FacesContext.getCurrentInstance(); ExternalContext externalContext = facesContext.getExternalContext(); externalContext.setResponseContentType("application/vnd.ms-excel"); externalContext.setResponseHeader("Content-Disposition", "attachment; filename=\"G-Cairo Region Extra Work.xlsx\""); try { workbook.write(externalContext.getResponseOutputStream()); externalContext.getResponseOutputStream().close(); } catch (IOException ex) { Logger.getLogger(ExportManager.class.getName()).log(Level.SEVERE, null, ex); } facesContext.responseComplete(); JsfUtil.addSuccessMessage("Activity Report is now exported"); } catch (InvalidFormatException ex) { Logger.getLogger(ExportManager.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ExportManager.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.vodafone.poms.ii.helpers.ExportManager.java
private static String addImageToSheet(XSSFSheet sh, int imgId, int pictureType) throws InvalidFormatException { final PackagePartName pnIMG = PackagingURIHelper.createPartName( "/xl/media/image" + (imgId + 1) + (pictureType == Workbook.PICTURE_TYPE_PNG ? ".png" : ".jpeg")); PackageRelationship prIMG = sh.getPackagePart().addRelationship(pnIMG, TargetMode.INTERNAL, PackageRelationshipTypes.IMAGE_PART); return prIMG.getId(); }
From source file:de.iteratec.iteraplan.businesslogic.exchange.elasticExcel.export.template.AbstractIntroSheetGenerator.java
License:Open Source License
private void insertIteraplanLogo(int colIndex, int rowIndex) { CreationHelper helper = getWorkbook().getCreationHelper(); byte[] bytes; try {//from ww w.ja v a 2 s . c o m InputStream is = logoImage.getInputStream(); bytes = IOUtils.toByteArray(is); } catch (IOException e) { LOGGER.error("Could not read the excel template!", e); throw new IteraplanTechnicalException(IteraplanErrorMessages.INVALID_EXCEL_TEMPLATE); } int pictureIdx = getWorkbook().addPicture(bytes, Workbook.PICTURE_TYPE_PNG); Sheet sheet = getIntroductionSheet(); Drawing drawing = sheet.createDrawingPatriarch(); ClientAnchor anchor = helper.createClientAnchor(); //set top-left corner of the picture anchor.setCol1(colIndex); anchor.setRow1(rowIndex); Picture pict = drawing.createPicture(anchor, pictureIdx); pict.resize(); }