OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Calc: inserting an image into worksheet

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
viffer
Newbie
Newbie


Joined: 19 Oct 2011
Posts: 3

PostPosted: Wed Oct 19, 2011 7:03 am    Post subject: Calc: inserting an image into worksheet Reply with quote

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
View user's profile Send private message
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10106
Location: Germany

PostPosted: Wed Oct 19, 2011 1:08 pm    Post subject: Reply with quote

Very simple with a database instead of code: [Solved] Best Approach for Images - Store or Link?
_________________
Rest in peace, oooforum.org
Get help on https://forum.openoffice.org
Back to top
View user's profile Send private message
viffer
Newbie
Newbie


Joined: 19 Oct 2011
Posts: 3

PostPosted: Fri Oct 21, 2011 1:13 am    Post subject: Reply with quote

Thank you appreciate the advice, but for now I'd like to use a spreadsheet.
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Fri Oct 21, 2011 9:05 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website AIM Address
viffer
Newbie
Newbie


Joined: 19 Oct 2011
Posts: 3

PostPosted: Sun Oct 23, 2011 11:29 pm    Post subject: Reply with quote

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
View user's profile Send private message
pig
General User
General User


Joined: 26 Jun 2012
Posts: 5

PostPosted: Tue Jul 17, 2012 11:30 pm    Post subject: Reply with quote

Villeroy wrote:
Very simple with a database instead of code: [Solved] Best Approach for Images - Store or Link?


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
View user's profile Send private message
mrfrabcabert
Newbie
Newbie


Joined: 18 Jul 2012
Posts: 1

PostPosted: Thu Jul 19, 2012 3:30 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group