hoja XSSFSheet = libro de trabajo.createSheet(String.valueOf(photoIndex));
XSSFRow headerRow = sheet.createRow(0); XSSFHyperlink link = creationHelper.createHyperlink(HyperlinkType.DOCUMENT); XSSFCell cellHeader1 = headerRow.createCell(0); cellHeader1.setCellValue("< Back to Issue List"); link.setAddress("'Issue List'!A1"); link.setLabel("< Back to Issue List"); cellHeader1.setHyperlink(link); cellHeader1.setCellStyle(numberFormatCellStyleWithHyperLink(workbook)); int col = 0, rowIndex = 1; for(String photosPath : serviceIssueDTO.getIssuePhotos()) { // Row for Photos XSSFRow row = sheet.createRow(rowIndex++); //FileInputStream obtains input bytes from the image file BufferedImage bimg = ImageIO.read(new File(GeneralPropertyAccessBean.imageUploadPath + photosPath)); int width = bimg.getWidth(); int height = bimg.getHeight(); InputStream inputStream = new FileInputStream(GeneralPropertyAccessBean.imageUploadPath + photosPath); //Get the contents of an InputStream as a byte[]. byte[] bytes = IOUtils.toByteArray(inputStream); //Adds a picture to the workbook int pictureIdx = workbook.addPicture(bytes, XSSFWorkbook.PICTURE_TYPE_JPEG); //close the input stream inputStream.close(); //Creates the top-level drawing patriarch. XSSFDrawing drawing = sheet.createDrawingPatriarch(); //Create an anchor that is attached to the worksheet XSSFClientAnchor anchor = creationHelper.createClientAnchor(); //create an anchor with upper left cell _and_ bottom right cell anchor.setCol1(col); //Column A anchor.setRow1(row.getRowNum()); //Row 1 anchor.setCol2(col+1); //Column B anchor.setRow2(row.getRowNum()+1); //Row 2 //Creates a picture XSSFPicture pict = drawing.createPicture(anchor, pictureIdx); row.createCell(col); sheet.setColumnWidth(col,(63*256)); row.setHeightInPoint[enter image description here][1]s(height); }
No puedo establecer el ancho y la altura de una celda de Excel de acuerdo con el ancho y la altura originales de la imagen. Configuré sheet.resize () pero no puedo trabajar, también configuré sheet.autosizeColumn () pero no puedo trabajar
No establece una imagen de altura y ancho de alto nivel en la celda en particular si desea establecer la altura y el ancho original de la imagen para que pueda dibujar la imagen en Excel, no establecer la imagen en la celda
for(String photosPath:serviceIssueDTO.getIssuePhotos()) { //FileInputStream obtains input bytes from the image file InputStream inputStream = new FileInputStream(GeneralPropertyAccessBean.imageUploadPath + photosPath); //Get the contents of an InputStream as a byte[]. byte[] bytes = IOUtils.toByteArray(inputStream); //Adds a picture to the workbook int pictureIdx = workbook.addPicture(bytes, XSSFWorkbook.PICTURE_TYPE_JPEG); //close the input stream inputStream.close(); //Creates the top-level drawing patriarch. XSSFDrawing drawing = sheet.createDrawingPatriarch(); //Creates a picture XSSFClientAnchor my_anchor = new XSSFClientAnchor(); my_anchor.setCol1(0); my_anchor.setRow1(row); XSSFPicture pict = drawing.createPicture(my_anchor, pictureIdx); row = (int) (row + Math.ceil(pict.getImageDimension().height/20) + 3); pict.resize(); }