Java Code Examples for org.apache.poi.ss.usermodel.Workbook#PICTURE_TYPE_WMF

The following examples show how to use org.apache.poi.ss.usermodel.Workbook#PICTURE_TYPE_WMF . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HSSFPictureData.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @return the POI internal image type, -1 if not unknown image type
 *
 * @see Workbook#PICTURE_TYPE_DIB
 * @see Workbook#PICTURE_TYPE_EMF
 * @see Workbook#PICTURE_TYPE_JPEG
 * @see Workbook#PICTURE_TYPE_PICT
 * @see Workbook#PICTURE_TYPE_PNG
 * @see Workbook#PICTURE_TYPE_WMF
 */
public int getPictureType() {
    switch (blip.getRecordId()) {
        case EscherMetafileBlip.RECORD_ID_WMF:
            return Workbook.PICTURE_TYPE_WMF;
        case EscherMetafileBlip.RECORD_ID_EMF:
            return Workbook.PICTURE_TYPE_EMF;
        case EscherMetafileBlip.RECORD_ID_PICT:
            return Workbook.PICTURE_TYPE_PICT;
        case EscherBitmapBlip.RECORD_ID_PNG:
            return Workbook.PICTURE_TYPE_PNG;
        case EscherBitmapBlip.RECORD_ID_JPEG:
            return Workbook.PICTURE_TYPE_JPEG;
        case EscherBitmapBlip.RECORD_ID_DIB:
            return Workbook.PICTURE_TYPE_DIB;
        default:
            return -1;
    }        
}
 
Example 2
Source File: AbstractExcelFactory.java    From myexcel with Apache License 2.0 4 votes vote down vote up
private void setImage(Td td, Sheet sheet) {
    if (td.getFile() == null) {
        return;
    }
    try {
        if (createHelper == null) {
            createHelper = workbook.getCreationHelper();
        }
        byte[] bytes = Files.readAllBytes(td.getFile().toPath());
        String fileName = td.getFile().getName();
        int format;
        String suffix = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
        switch (suffix) {
            case "jpg":
            case "jpeg":
                format = Workbook.PICTURE_TYPE_JPEG;
                break;
            case "png":
                format = Workbook.PICTURE_TYPE_PNG;
                break;
            case "dib":
                format = Workbook.PICTURE_TYPE_DIB;
                break;
            case "emf":
                format = Workbook.PICTURE_TYPE_EMF;
                break;
            case "pict":
                format = Workbook.PICTURE_TYPE_PICT;
                break;
            case "wmf":
                format = Workbook.PICTURE_TYPE_WMF;
                break;
            default:
                throw new IllegalArgumentException("Invalid image type");
        }
        int pictureIdx = workbook.addPicture(bytes, format);
        Drawing drawing = sheet.createDrawingPatriarch();
        ClientAnchor anchor = createHelper.createClientAnchor();
        anchor.setCol1(td.getCol());
        anchor.setRow1(td.getRow());
        Picture pict = drawing.createPicture(anchor, pictureIdx);
        pict.resize(1, 1);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}