| View previous topic :: View next topic |
| Author |
Message |
viffer Newbie

Joined: 19 Oct 2011 Posts: 3
|
Posted: Wed Oct 19, 2011 7:03 am Post subject: Calc: inserting an image into worksheet |
|
|
Hi all
Firstly, apologies if this has been dealt with elsewhere, I did a search and nothing applicable came back.
I'm looking for a macro that will insert an image into a calc worksheet. The destination is some merged cells and I have a button in place that will run the macro. Basically, what I want is to press the insert button and a file requestor dialog pops up allowing me to select an image file which is then inserted and sized to fit in the destination cell.
Thats it really, I've spent a few hours looking around and found bits and pieces but nothing specific, so thought it worth asking the question on here.
Thanks in advance
viffer
Moderation probe1: moved to MACROS AND API section, where all macro related questions belong to; edited subject |
|
| Back to top |
|
 |
Villeroy Super User


Joined: 04 Oct 2004 Posts: 10065 Location: Germany
|
|
| Back to top |
|
 |
viffer Newbie

Joined: 19 Oct 2011 Posts: 3
|
Posted: Fri Oct 21, 2011 1:13 am Post subject: |
|
|
| Thank you appreciate the advice, but for now I'd like to use a spreadsheet. |
|
| Back to top |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3622 Location: Columbus, Ohio, USA
|
Posted: Fri Oct 21, 2011 9:05 pm Post subject: |
|
|
At least one of my documents demonstrates how to add an image to a document.... AndrewMacro.odt, for example. If you use OOo, it will crash when you close the document (but in OOo), LibreOffice will not. _________________ --
Andrew Pitonyak
http://www.pitonyak.org/oo.php |
|
| Back to top |
|
 |
viffer Newbie

Joined: 19 Oct 2011 Posts: 3
|
Posted: Sun Oct 23, 2011 11:29 pm Post subject: |
|
|
Andrew
Thank you for the response. Yes I am aware of your document and you are correct in that there are examples of how to insert an image in to a document contained within.
I actually spent several hours going through the document on Thursday trying out code and generally reading things through.
I have to say that it is an excellent all round resource so thanks for making it available. However, the examples in the document assume a user wants to insert a named file in a specific location ie c:\temp\pic.jpg. That's fine for one offs but I use the worksheet for a repetitive task and would much rather I could open a file dialogue box and manually select a file rather than have to save each file as c:\temp\pic.jpg.
The main requirement is to be able to select an image file and to insert it and resize it to suit - this is where I am at the moment. The icing on the cake would be to be able to select a file irrespective of name/location and then autiomatically insert & resize.
Thanks for the assistance
Viffer |
|
| Back to top |
|
 |
pig General User

Joined: 26 Jun 2012 Posts: 5
|
Posted: Tue Jul 17, 2012 11:30 pm Post subject: |
|
|
Hello! The address not connect.To insert the picture in the calc example can be sent to my mailbox, I have been to find the relevant information
email : huangone111@sina.com |
|
| Back to top |
|
 |
mrfrabcabert Newbie

Joined: 18 Jul 2012 Posts: 1
|
Posted: Thu Jul 19, 2012 3:30 am Post subject: |
|
|
A simple way I did it was to record a macro of me inserting an image into a certain cell, and then open the macro code and remove the first arg. See example.
sub imageimport
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dim args1(2) as new com.sun.star.beans.PropertyValue
args1(0).Name = "FileName"
args1(0).Value = "file:///C:/dominante/4009654.jpg" <---- delete red portion
args1(1).Name = "FilterName"
args1(1).Value = "JPEG - Joint Photographic Experts Group"
args1(2).Name = "AsLink"
args1(2).Value = false
dispatcher.executeDispatch(document, ".uno:InsertGraphic", "", 0, args1())
rem ----------------------------------------------------------------------
dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = "ToPoint"
args2(0).Value = "$G$13"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args2())
end sub
but like you, I would love to know how to have a file name in a cell and have a macro open that image using the cell as filename. |
|
| Back to top |
|
 |
|