List of usage examples for org.apache.poi.ss.usermodel Picture resize
void resize();
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 a2 s .co 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.github.cutstock.excel.model.SheetBuilder.java
License:Apache License
private void createLogoImage(ICellInfo title) { Workbook wb = sheet.getWorkbook();/*from ww w . ja v a2 s . co m*/ int pictureIdx = wb.addPicture(title.getImage(), Workbook.PICTURE_TYPE_JPEG); CreationHelper helper = wb.getCreationHelper(); Drawing drawing = sheet.createDrawingPatriarch(); ClientAnchor anchor = helper.createClientAnchor(); anchor.setCol1(title.getRect().getStartCol()); anchor.setRow1(title.getRect().getStartRow()); Picture pict = drawing.createPicture(anchor, pictureIdx); pict.resize(); }
From source file:com.griffinslogistics.document.excel.BDLGenerator.java
private static void insertPulsioImage(Workbook workbook, Sheet sheet, Pulsiodetails pulsiodetails) { Row imageRow = sheet.createRow(0);/*from w w w . jav a 2 s.c om*/ 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(7); anchor.setRow1(0); Picture pict = drawing.createPicture(anchor, pictureIdx); pict.resize(); }
From source file:com.griffinslogistics.excel.BDLGenerator.java
private static void insertPulsioImage(Workbook workbook, Sheet sheet, Pulsiodetails pulsiodetails) { Row imageRow = sheet.createRow(0);// w w w . jav a2 s . co m 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); anchor.setRow1(0); Picture pict = drawing.createPicture(anchor, pictureIdx); pict.resize(); }
From source file:com.griffinslogistics.excel.CMRGenerator.java
private static int generatePoint20Till24(XSSFSheet sheet, Map<String, CellStyle> styles, int currentRow, Pulsiodetails pulsiodetails) {/*from w ww .j a va 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_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.miraisolutions.xlconnect.Workbook.java
License:Open Source License
public void addImage(File imageFile, String name, boolean originalSize) throws FileNotFoundException, IOException { Name cname = getName(name);/*from www . j a va2 s.com*/ // Get sheet where name is defined in Sheet sheet = workbook.getSheet(cname.getSheetName()); AreaReference aref = new AreaReference(cname.getRefersToFormula()); // Get name corners (top left, bottom right) CellReference topLeft = aref.getFirstCell(); CellReference bottomRight = aref.getLastCell(); // Determine image type int imageType; String filename = imageFile.getName().toLowerCase(); if (filename.endsWith("jpg") || filename.endsWith("jpeg")) { imageType = org.apache.poi.ss.usermodel.Workbook.PICTURE_TYPE_JPEG; } else if (filename.endsWith("png")) { imageType = org.apache.poi.ss.usermodel.Workbook.PICTURE_TYPE_PNG; } else if (filename.endsWith("wmf")) { imageType = org.apache.poi.ss.usermodel.Workbook.PICTURE_TYPE_WMF; } else if (filename.endsWith("emf")) { imageType = org.apache.poi.ss.usermodel.Workbook.PICTURE_TYPE_EMF; } else if (filename.endsWith("bmp") || filename.endsWith("dib")) { imageType = org.apache.poi.ss.usermodel.Workbook.PICTURE_TYPE_DIB; } else if (filename.endsWith("pict") || filename.endsWith("pct") || filename.endsWith("pic")) { imageType = org.apache.poi.ss.usermodel.Workbook.PICTURE_TYPE_PICT; } else throw new IllegalArgumentException( "Image type \"" + filename.substring(filename.lastIndexOf('.') + 1) + "\" not supported!"); InputStream is = new FileInputStream(imageFile); byte[] bytes = IOUtils.toByteArray(is); int imageIndex = workbook.addPicture(bytes, imageType); is.close(); Drawing drawing; if (isHSSF()) { drawing = ((HSSFSheet) sheet).getDrawingPatriarch(); if (drawing == null) { drawing = sheet.createDrawingPatriarch(); } } else if (isXSSF()) { drawing = ((XSSFSheet) sheet).createDrawingPatriarch(); } else { drawing = sheet.createDrawingPatriarch(); } CreationHelper helper = workbook.getCreationHelper(); ClientAnchor anchor = helper.createClientAnchor(); anchor.setRow1(topLeft.getRow()); anchor.setCol1(topLeft.getCol()); // +1 since we want to include the anchor.setRow2(bottomRight.getRow() + 1); anchor.setCol2(bottomRight.getCol() + 1); anchor.setAnchorType(ClientAnchor.DONT_MOVE_AND_RESIZE); Picture picture = drawing.createPicture(anchor, imageIndex); if (originalSize) picture.resize(); }
From source file:Compras.altaCompras.java
private void b_muestraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_muestraActionPerformed // TODO add your handling code here: javax.swing.JFileChooser jF1= new javax.swing.JFileChooser(); jF1.setFileFilter(new ExtensionFileFilter("Excel document (*.xls)", new String[] { "xls" })); String ruta = null;/* w ww . j a v a 2s.com*/ if(jF1.showSaveDialog(null)==jF1.APPROVE_OPTION) { ruta = jF1.getSelectedFile().getAbsolutePath(); File archivoXLS = new File(ruta+".xls"); try { if(archivoXLS.exists()) archivoXLS.delete(); archivoXLS.createNewFile(); Workbook libro = new HSSFWorkbook(); FileOutputStream archivo = new FileOutputStream(archivoXLS); Sheet hoja = libro.createSheet("Muestras"); org.apache.poi.ss.usermodel.Font font10 = libro.createFont(); font10.setFontHeightInPoints((short)10); font10.setFontName("Arial"); font10.setItalic(false); font10.setBold(false); font10.setColor(new HSSFColor.YELLOW().getIndex()); CellStyle titulo = libro.createCellStyle(); CellStyle contenido = libro.createCellStyle(); CellStyle firma = libro.createCellStyle(); CellStyle costado = libro.createCellStyle(); CellStyle derecha = libro.createCellStyle(); CellStyle derecha_borde = libro.createCellStyle(); titulo.setFont(font10); titulo.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); titulo.setFillBackgroundColor(new HSSFColor.GREEN().getIndex()); titulo.setAlignment(CellStyle.ALIGN_CENTER); contenido.setBorderBottom(HSSFCellStyle.BORDER_THIN); contenido.setBorderTop(HSSFCellStyle.BORDER_THIN); contenido.setBorderRight(HSSFCellStyle.BORDER_THIN); contenido.setBorderLeft(HSSFCellStyle.BORDER_THIN); derecha_borde.setBorderBottom(HSSFCellStyle.BORDER_THIN); derecha_borde.setBorderTop(HSSFCellStyle.BORDER_THIN); derecha_borde.setBorderRight(HSSFCellStyle.BORDER_THIN); derecha_borde.setBorderLeft(HSSFCellStyle.BORDER_THIN); derecha_borde.setAlignment(CellStyle.ALIGN_RIGHT); derecha.setAlignment(CellStyle.ALIGN_RIGHT); firma.setBorderTop(HSSFCellStyle.BORDER_THIN); firma.setAlignment(CellStyle.ALIGN_CENTER); //costado.setBorderLeft(HSSFCellStyle.BORDER_THIN); hoja.setColumnWidth(0, 3000); hoja.setColumnWidth(2, 3000); hoja.setColumnWidth(3, 8000); hoja.setColumnWidth(4, 5000); try { InputStream is = new FileInputStream("imagenes/grande300115.jpg"); byte[] bytes = IOUtils.toByteArray(is); int pictureIdx = libro.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG); is.close(); CreationHelper helper = libro.getCreationHelper(); Drawing drawing = hoja.createDrawingPatriarch(); ClientAnchor anchor = helper.createClientAnchor(); anchor.setCol1(0); anchor.setRow1(0); Picture pict = drawing.createPicture(anchor, pictureIdx); pict.resize(); }catch(Exception e){e.printStackTrace();} Row r7 = hoja.createRow(7); r7.createCell(0).setCellValue("ORDEN:"); r7.createCell(1).setCellValue(String.valueOf(ord.getIdOrden())); r7.createCell(2).setCellValue("Hrs. Entrega:"); r7.createCell(3).setCellValue(""); hoja.addMergedRegion(new CellRangeAddress(7,7,4,7)); r7.createCell(4).setCellValue("ORDEN PARA SURTIR MUESTRAS"); r7.getCell(4).setCellStyle(derecha); Date fecha = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");//YYYY-MM-DD HH:MM:SS String valor=dateFormat.format(fecha); Row r8 = hoja.createRow(8); r8.createCell(0).setCellValue("Supervisor:"); hoja.addMergedRegion(new CellRangeAddress(8,8,1,3)); r8.createCell(1).setCellValue(""); r8.createCell(4).setCellValue("F. Elaboracin:"); r8.createCell(5).setCellValue(valor); Row r9 = hoja.createRow(9); r9.createCell(0).setCellValue("Comprador:"); hoja.addMergedRegion(new CellRangeAddress(9,9,1,3)); r9.createCell(1).setCellValue(""); r9.createCell(4).setCellValue("F. Entrega:"); r9.createCell(5).setCellValue(""); Row r10 = hoja.createRow(10); r10.createCell(0).setCellValue("Cantidad"); r10.getCell(0).setCellStyle(titulo); hoja.addMergedRegion(new CellRangeAddress(10,10,1,7)); r10.createCell(1).setCellValue("Descripcin"); r10.getCell(1).setCellStyle(titulo); int ren=11; for(int r=0;r<(t_datos.getRowCount());r++) { if((boolean)t_titulos.getValueAt(r, 3)==true) { Row fila = hoja.createRow(ren); Cell celda = fila.createCell(0); celda.setCellStyle(derecha_borde); Cell celda1 = fila.createCell(1); celda1.setCellStyle(contenido); fila.createCell(2).setCellStyle(contenido); fila.createCell(3).setCellStyle(contenido); fila.createCell(4).setCellStyle(contenido); fila.createCell(5).setCellStyle(contenido); fila.createCell(6).setCellStyle(contenido); fila.createCell(7).setCellStyle(contenido); //Cell celda8 = fila.createCell(8); //celda8.setCellStyle(costado); try{ celda.setCellValue(t_datos.getValueAt(r, 14).toString()); hoja.addMergedRegion(new CellRangeAddress(ren,ren,1,7)); celda1.setCellValue(t_titulos.getValueAt(r, 2).toString()); //celda8.setCellValue(""); }catch(Exception e){ celda.setCellValue(""); } ren++; } } Row rx = hoja.createRow(ren+5); hoja.addMergedRegion(new CellRangeAddress(ren+5,ren+5,0,2)); rx.createCell(0).setCellValue("Recibe Muestras"); rx.getCell(0).setCellStyle(firma); rx.createCell(1).setCellStyle(firma); rx.createCell(2).setCellStyle(firma); hoja.addMergedRegion(new CellRangeAddress(ren+5,ren+5,5,7)); rx.createCell(5).setCellValue("Entrega Muestras"); rx.getCell(5).setCellStyle(firma); rx.createCell(6).setCellStyle(firma); rx.createCell(7).setCellStyle(firma); libro.write(archivo); archivo.close(); Desktop.getDesktop().open(archivoXLS); }catch(Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto"); } } }
From source file:controller.VisitasController.java
public void exportExcel() { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Open Resource File"); fileChooser.setInitialDirectory(new File(System.getProperty("user.home"))); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("XLS", "*.xls")); File f = fileChooser.showSaveDialog(null); try {// ww w . ja va2 s . c o m String filename = f.getAbsolutePath(); HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("FirstSheet"); int bool = 1; InputStream inputStream = getClass().getResourceAsStream("/images/excel-logo.jpg"); byte[] imageBytes = IOUtils.toByteArray(inputStream); int pictureureIdx = workbook.addPicture(imageBytes, Workbook.PICTURE_TYPE_JPEG); inputStream.close(); CreationHelper helper = workbook.getCreationHelper(); Drawing drawing = sheet.createDrawingPatriarch(); ClientAnchor anchor = helper.createClientAnchor(); anchor.setCol1(1); anchor.setRow1(0); Picture pict = drawing.createPicture(anchor, pictureureIdx); HSSFRow rowhead = sheet.createRow(8); rowhead.createCell(0); rowhead.createCell(1).setCellValue("Cedula"); rowhead.createCell(2).setCellValue("Cliente"); rowhead.createCell(3).setCellValue("Contrato"); rowhead.createCell(4).setCellValue("Plan"); rowhead.createCell(5).setCellValue("Fecha"); rowhead.createCell(6).setCellValue("Hora"); rowhead.createCell(7).setCellValue("Invitados"); makeRowBold(workbook, rowhead); for (int i = 0; i < table.getItems().size(); i++) { HSSFRow row = sheet.createRow(i + 9); Asistencia a = (Asistencia) table.getItems().get(i); row.createCell(1).setCellValue(a.getCedula()); row.createCell(2).setCellValue(a.getNombre()); row.createCell(3).setCellValue(a.getContrato()); row.createCell(4).setCellValue(a.getPlan()); row.createCell(5).setCellValue(a.getFecha()); row.createCell(6).setCellValue(a.getHora()); row.createCell(7).setCellValue(Integer.parseInt(a.getInvitados())); centerRow(workbook, row); } autoSizeColumns(workbook); pict.resize(); FileOutputStream fileOut = new FileOutputStream(filename); workbook.write(fileOut); fileOut.close(); } catch (Exception ex) { ex.printStackTrace(); } }
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 w w w . ja va2s. 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(); }
From source file:functions.excels.Excel.java
License:Apache License
/** * Colle le logo en haut gauche de la page donne. * @param page/*from w w w . ja v a2s .c o m*/ * @throws IOException */ public void collerLogo(int page) throws IOException { InputStream is = new FileInputStream("public/images/banniere-aer.png"); byte[] bytes = IOUtils.toByteArray(is); int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_PNG); is.close(); CreationHelper helper = wb.getCreationHelper(); Sheet sheet = wb.getSheetAt(0); // Create the drawing patriarch. This is the top level container for all shapes. Drawing drawing = sheet.createDrawingPatriarch(); //add a picture shape ClientAnchor anchor = helper.createClientAnchor(); //set top-left corner of the picture, //subsequent call of Picture#resize() will operate relative to it anchor.setCol1(0); anchor.setRow1(LIGNES * page); Picture pict = drawing.createPicture(anchor, pictureIdx); //auto-size picture relative to its top-left corner pict.resize(); }