Sorry I have not been able to make more progress on this problem but with the
good weather our clients are pressing us to complete work on a number of
contracts.

Anyway Matthew, I have made a little more progress - getting rid of all the
duplicate records so that now, the code only returns a single opt and anchor
record for each image. The change was very simple really once I understood
that containers were also child records. Have a look at the modified
iterateContainer() method to see what I mean;

private void iterateContainer(EscherContainerRecord escherContainer, int
level) {
        List childRecords = escherContainer.getChildRecords();
        Iterator listIterator = null;
        org.apache.poi.ddf.EscherSpgrRecord sprgRecord = null;
        org.apache.poi.ddf.EscherSpRecord spRecord = null;
        org.apache.poi.ddf.EscherOptRecord optRecord = null;
        org.apache.poi.ddf.EscherClientAnchorRecord anchrRecord = null;
        org.apache.poi.ddf.EscherClientDataRecord dataRecord = null;
        org.apache.poi.ddf.EscherDgRecord dgRecord = null;
        Object next = null;
        
        listIterator = childRecords.iterator();
        while(listIterator.hasNext()) {
            next = listIterator.next();
            if(next instanceof org.apache.poi.ddf.EscherContainerRecord) {
               
this.iterateContainer((org.apache.poi.ddf.EscherContainerRecord)next,
++level);
            }
            else {
                if(next instanceof org.apache.poi.ddf.EscherOptRecord) {
                    optRecord = (org.apache.poi.ddf.EscherOptRecord)next;
                    String key = String.valueOf(level);
                    if(this.shapes.containsKey(key)) {
                        this.shapes.get(key).setOptRecord(optRecord);
                    }
                    else {
                        ShapeInformation shape = new
ShapeInformation(level);
                        shape.setOptRecord(optRecord);
                        this.shapes.put(key, shape);
                    }
                }
                else if(next instanceof
org.apache.poi.ddf.EscherClientAnchorRecord) {
                    anchrRecord =
(org.apache.poi.ddf.EscherClientAnchorRecord)next;
                    String key = String.valueOf(level);
                    if(this.shapes.containsKey(key)) {
                        this.shapes.get(key).setAnchorRecord(anchrRecord);
                    }
                    else {
                        ShapeInformation shape = new
ShapeInformation(level);
                        shape.setAnchorRecord(anchrRecord);
                        this.shapes.put(key, shape);
                    }
                }
            }
        }
    }

There are still a few challenges - chief amongst them being how to match the
opt/anchor record combination to an actual image though I am going to guess
this should be possible as one of the properties of the opt record returns
something that looks like the path to and name of the picture.

Hopefully, I will be able to work on this code a little more tonight and I
will post if there is any progress.



matthewxb wrote:
> 
> I have a workbook contains two pictures. I want to copy the pictures from
> a source workbook to a target workbook. How can I do that?
> 
> I used HSSFWorkbook.getAllPictures() to retrieve all the pictures, but it
> only allow me to read the pictures' binary data. I have to know the size
> and the location of each picture.
> I write a loop to read each worksheet and call
> HSSFSheet.getDrawingPatriarch(). It contains four methods in
> HSSFPatriarch, suppose they represent the location of picture.
>       
>       HSSFPatriarch.getX1(),HSSFPatriarch.getX2(), HSSFPatriarch.getY1(),
> HSSFPatriarch.getY2()
>       
> But above methods return 0, which is incorrect.
> 
> And the size of picture I couldn't find a way to know, since the actual
> picture size and the size shown in worksheet are different.
> 
> I want to copy the pictures from a source workbook to a target workbook.
> How can I do that? Please advice, thank you very much!
> 

-- 
View this message in context: 
http://www.nabble.com/Copy-images-from-Workbook-to-Workbook-tp23032425p23156516.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to