Example usage for org.apache.poi.xssf.usermodel XSSFClientAnchor getCol1

List of usage examples for org.apache.poi.xssf.usermodel XSSFClientAnchor getCol1

Introduction

In this page you can find the example usage for org.apache.poi.xssf.usermodel XSSFClientAnchor getCol1.

Prototype

public short getCol1() 

Source Link

Usage

From source file:nc.noumea.mairie.appock.services.impl.ImportExcelServiceImpl.java

License:Open Source License

private PhotoArticleCatalogue recuperePhotoArticleCatalogue(XSSFSheet firstSheet, String nomFichier, int numRow,
        String reference) throws IOException, ImportExcelException {

    Stream<XSSFShape> shapeStream = firstSheet.getDrawingPatriarch().getShapes().stream() //
            .filter(shape -> {//  w  ww .jav  a  2s.c  om
                if (!(shape instanceof XSSFPicture)) {
                    return false;
                }
                XSSFPicture picture = (XSSFPicture) shape;
                XSSFClientAnchor anchor = (XSSFClientAnchor) picture.getAnchor();
                XSSFRow pictureRow = firstSheet.getRow(anchor.getRow1());
                return (anchor.getCol1() == IMPORT_EXCEL_COLONNE_PHOTO && pictureRow != null
                        && pictureRow.getRowNum() == numRow);
            });

    List<XSSFShape> listeShape = shapeStream.collect(Collectors.toList());
    if (listeShape.isEmpty()) {
        throw new ImportExcelException(numRow + 1, reference, "Aucune image n'a t trouve");
    } else if (listeShape.size() > 1) {
        throw new ImportExcelException(numRow + 1, reference, "Plusieurs images ont t trouves");
    }

    XSSFPicture picture = (XSSFPicture) listeShape.get(0);
    byte[] content = picture.getPictureData().getData();
    content = AppockUtil.scale(content, 80, 80);

    if (content == null) {
        throw new ImportExcelException(numRow + 1, reference, "Aucune image n'a t trouve");
    }

    return catalogueService.savePhotoArticleCatalogue(content, nomFichier);
}