We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How can I get images from worksheet

Hi,

I want to count images on workbook. I try with this Java code :

com.aspose.cells.Workbook workbook = new com.aspose.cells.Workbook(sFullNameIn);
com.aspose.cells.TxtSaveOptions opts = new com.aspose.cells.TxtSaveOptions();
opts.setSeparator(’\t’);
for (int idx = 0; idx < workbook.getWorksheets().getCount(); idx++) {
System.out.println(“worksheet====================”+idx);
for (int j = 0; j < workbook.getWorksheets().get(idx).getShapes().getCount(); j++) {
com.aspose.cells.Shape shape = workbook.getWorksheets().get(idx).getShapes().get(j);
System.out.println( "shape “+j+” : “+shape.getName()+” type “+shape.getType()+” = "+shape.getText());
}
}

I can’t tell which one are images because Shapes are not just images but include comments, groups, text boxes, charts, arrows etc.
And some shapes have their own specific name as this example result here:

worksheet====================4
shape 0 : Chart 1 type 201 = null
shape 1 : テキスト ボックス 1 type 202 = null
shape 2 : テキスト ボックス 2 type 202 = 千円

So, I cannot identify image from shapes’ name also.

Please advise how can I identify the actual images.

Regards,
Rapeepan

@rcomniscien,

Please try using Shape.getMsoDrawingType() enum for your needs. See the following sample code for your requirements for your reference:
e.g
Sample code:

    Workbook wb = new Workbook("e:\\test2\\sample-controls.xlsx");

        Worksheet ws = wb.getWorksheets().get(0);

        int cnt = ws.getShapes().getCount();
        System.out.println(cnt);
        for (int j = 0; j < cnt;  j++)	
        {
            Shape shape = ws.getShapes().get(j);
            //System.out.println( "shape "+j+" : "+shape.getName()+" drawaing type "+shape.getMsoDrawingType()+" = "+shape.getText());
            //if (shape.getType())	
            //{
            
            switch (shape.getMsoDrawingType())

            {

                case MsoDrawingType.PICTURE:
                    System.out.println("shape: " + shape.getName() + " is an image"); 
                    break;

                case MsoDrawingType.CHART:
                	System.out.println("shape: " + shape.getName() + " is a chart"); 
                    break;

                case MsoDrawingType.CHECK_BOX:
                	System.out.println("shape: " + shape.getName() + " is a checkbox"); 
                    break;

                case MsoDrawingType.COMBO_BOX:
                	System.out.println("shape: " + shape.getName() + "is a combo box"); 
                    break;
                    
                case MsoDrawingType.COMMENT:
                	System.out.println("shape: " + shape.getName() + "is a comment shape"); 
                    break;
                    
                case MsoDrawingType.TEXT_BOX:
                	System.out.println("shape: " + shape.getName() + " is a text box"); 
                    break;

                case MsoDrawingType.BUTTON:
                	System.out.println("shape: " + shape.getName() + "is a button"); 
                    break;
                    
                default:

                    
                    break;

            } } 

Hope, this helps a bit.

That’s helpful. Thank you.

@rcomniscien,

Good to know that the sample code sorts our your issue. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.