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

Insert an image into a spreadsheet

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


Joined: 05 Oct 2004
Posts: 2

PostPosted: Tue Oct 05, 2004 2:17 am    Post subject: Insert an image into a spreadsheet Reply with quote

Hi,
Using Delphi Im trying to insert an image into a spreadsheet/cell...

This is what I have so far:

Code:

var
  dispatcher, xSheet, vImage, xTextCursor,
  aPoint, aSize, xCell: Variant;
begin
  xSheet := Desk.getSpreadsheet(0);
  xCell := xSheet.getCellByPosition( 1, 1 );
  xTextCursor := xCell.createTextCursor;
  vImage:= Desk.getDocument.createInstance('com.sun.star.drawing.GraphicObjectShape');
  vImage.setPropertyValue('GraphicURL', 'file:///C:/1.jpg');
  xCell.insertString(xTextCursor, vImage, false);          // <===== heres the problem
end;


can you please direct me to the right place.. all the examples I found were for VB and in the docs there was no reference for adding a pci.

Thanks,
Ariel.
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


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

PostPosted: Tue Oct 05, 2004 3:55 am    Post subject: Reply with quote

Although I do not know off hand how to insert a graphics image into a cell (I need to look it up), I know exactly why your code fails....
Code:
xCell.insertString(xTextCursor, vImage, false);

Inserts a string, not a graphics image. You probably want to use insertTextContent if you use a text cursor. You can not insert a GraphicsObjectShape this way, however. Grab my free document and search the document for GraphicObjectShape. I know for certain that you will want to take a look at sections

Quote:
If you create a GraphicObjectShape, then you must also set the size and in some document types, you may need to set the position. Notice that this next method adds the graphics image to the draw page rather than as a text item into the document.

Code:
Sub AddLinkedGraphicObjectIntoDoc
  REM Author: Andrew Pitonyak
  Dim sGraphURL As String
  Dim oGraph
  Dim oCurs
  Dim oText
  sGraphURL = "file:///c:/test2.jpg"

  REM When adding a graphic using this method, I must set the size manually. 
  oGraph = ThisComponent.createInstance("com.sun.star.drawing.GraphicObjectShape")
  oGraph.GraphicURL = sGraphURL
 
  REM Size the object
  Dim TheSize As New com.sun.star.awt.Size
  TheSize.width=1440
  TheSize.height=1440
  oGraph.setsize(TheSize)
  REM You can also insert this as text content if you desire.
  ThisComponent.Drawpage.add(oGraph)
End Sub

Section 5.30.1 has an example for a spreadsheet.
Code:
Sub InsertAndPositionGraphic
  REM Get the sheet
  Dim vSheet
  vSheet = ThisComponent.Sheets(0)

  REM Add the graphics object
  Dim oDesktop As Object, oDocument As Object
  Dim mNoArgs()
  Dim sGraphicURL As String
  Dim sGraphicService As String, sUrl As String
  Dim oDrawPages As Object, oDrawPage As Object
  Dim oGraphic As Object
  sGraphicURL = "file:///usr/local/openoffice1.1RC/share/gallery/bullets/blkpearl.gif"
  sGraphicService = "com.sun.star.drawing.GraphicObjectShape"
  oDrawPage = vSheet.getDrawPage()
  oGraphic = ThisComponent.createInstance(sGraphicService)
  oGraphic.GraphicURL = sGraphicURL
  oDrawPage.add(oGraphic)

  REM Size the object
  Dim TheSize As New com.sun.star.awt.Size
  TheSize.width=400
  TheSize.height=400
  oGraphic.setsize(TheSize)

  REM Position the object
  Dim aPosition As New com.sun.star.awt.Point
  aPosition.X = 2540
  aPosition.Y = 2540
  oGraphic.setposition(aPosition)
End Sub


I have seen other examples that make certain that the graphic is inserted at a cell. You may be able to insert a text content graphiic into a cell's text object, but I have not tried it.
_________________
--
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
tanffn
Newbie
Newbie


Joined: 05 Oct 2004
Posts: 2

PostPosted: Tue Oct 05, 2004 7:52 am    Post subject: Reply with quote

Thank you for the fast reply,
just one small thing how do I write:

Code:
Dim TheSize As New com.sun.star.awt.Size


in Delphi?

Thanks,
Ariel.
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