Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Adding pictures to Excel

by davies (Prior)
on Jan 23, 2010 at 16:46 UTC ( [id://819198]=note: print w/replies, xml ) Need Help??


in reply to Re: Adding pictures to Excel
in thread Adding pictures to Excel

In my experience, it's very rare to need to use the active cell for anything. But you're quite right, setting the active cell changes the import point. I, as Psmith would say, confused the unusual with the impossible. It's still ugly - I want my users to run my macros and end up back where they started. But I have Gargled extensively and found no way of putting a picture over a cell directly except by using the active cell. However, I have found an improvement on my previous code. Rather than the loops to work out the top and left of the target cell, the following works:
$nVPos = $rTarget->Top; $nHPos = $rTarget->Left;
And these can be refactored into the assignments so that the lines become something like:
$picCurrent->{Top} = $rTarget->{Top}; $picCurrent->{Left} = $rTarget->{Left};
Anchoring in this way means that inserting or deleting rows and columns moves the picture, so I think we now get the best of all worlds.

Thanks, all - I've learned something new about the tool that pays my bills!

John Davies

Replies are listed 'Best First'.
Re^3: Adding pictures to Excel
by Albannach (Monsignor) on Jan 23, 2010 at 17:42 UTC
    Of course that's a good point that the starting location in the sheet is lost. I didn't consider that because if this is being done just to create reports in Excel (my normal use) then it really shouldn't matter as the user has never been in the sheet to begin with, but in the case of an existing sheet, it is an issue. I do like your idea of adjusting location after insertion, it seems neater than jumping around on the sheet and would only be improved if Excel would allow one to specify the insertion point to start with.

    I tested a bit and your method appears to have the same results as inserting in the active cell too, with respect to effects of row and column insertion/resizing shifting the cell later. I wondered if your method would associate the image with an absolute sheet location (which might even be handy in some cases), but it appears to link to the cell location, so all in all I think you have the winner!

    --
    I'd like to be able to assign to an luser

Re^3: Adding pictures to Excel
by merrymonk (Hermit) on Jan 23, 2010 at 17:03 UTC
    Even better!! Great.
Re^3: Adding pictures to Excel
by merrymonk (Hermit) on Jan 24, 2010 at 17:52 UTC
    I have tested more with this and confirmed that the pictures are placed where I wanted them to be.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://819198]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-18 20:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found