?
Solved

Issue inserting graphic into Openoffice writer document using python

Posted on 2010-11-25
4
Medium Priority
?
1,049 Views
Last Modified: 2012-05-10
Here's the script I have so far:

 
import Danny.OOo.OOoLib as OOoLib
import unohelper
import os.path
import glob
from com.sun.star.beans import PropertyValue
from array import array

L =  [ PropertyValue() for i in range(4)]


L[0].Name="FileName"
L[0].Value="file://home/ollie/Desktop/Screenshot.png"
L[1].Name="FilterName"
L[1].Value="<All formats>"
L[2].Name = "AsLink"
L[2].Value = False
L[3].Name="Style"
L[3].Value="Graphics"


desktop = OOoLib.getDesktop()
doc=desktop.getCurrentComponent()
dispatcher = OOoLib.getServiceManager().createInstance('com.sun.star.frame.DispatchHelper')
dispatcher.executeDispatch(doc, ".uno:InsertGraphic", "", 0, tuple(L))

Open in new window


The error message I'm getting is:

Traceback (most recent call last):
  File "test.py", line 43, in ?
    dispatcher.executeDispatch(doc, ".uno:InsertGraphic", "", 0, tuple(L))
__main__.com.sun.star.script.CannotConvertException: value has no such interface!
0
Comment
Question by:opike
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
markoilic earned 2000 total points
ID: 34213005
Hi

if you look in previous thread about this topic you will that doc in line call another method to return current controller interface

doc.getCurrentController()

dispatcher.executeDispatch(doc.getCurrentController(), '.uno:InsertGraphic', '', 0, tuple(L))

or you can change line 21
doc=desktop.getCurrentComponent().getCurrentController()
in this case OpenOffice document (wrtier or calc) should be openerd

If you may want to open new instance of calc

instance = desktop.loadComponentFromURL('private:factory/scalc', '_blank', 0, ())
dispatcher.executeDispatch(instance.getCurrentController(), ".uno:InsertGraphic", "", 0, tuple(L))

this code will insert image in new opened call document

0
 

Author Comment

by:opike
ID: 34220785
"if you look in previous thread about this topic you will that doc in line call another method to return current controller interface

doc.getCurrentController()"

Yeah, sorry I was focused on the tuple() part and missed that you had made a change to that part too. But even when I change my code to this:

 
import Danny.OOo.OOoLib as OOoLib
import unohelper
import os.path
import glob
from com.sun.star.beans import PropertyValue
from array import array


L =  [ PropertyValue() for i in range(4)]


L[0].Name="FileName"
L[0].Value="file://home/ollie/Desktop/Screenshot.png"
L[1].Name="FilterName"
L[1].Value="<All formats>"
L[2].Name = "AsLink"
L[2].Value = False
L[3].Name="Style"
L[3].Value="Graphics"


desktop = OOoLib.getDesktop()
doc=desktop.getCurrentComponent()
dispatcher = OOoLib.getServiceManager().createInstance('com.sun.star.frame.DispatchHelper')
dispatcher.executeDispatch(doc.getCurrentController(), ".uno:InsertGraphic", "", 0, tuple(L))

Open in new window


No image is inserted.

I have a document open in Writer as I run the script.
0
 
LVL 2

Expert Comment

by:markoilic
ID: 34221450
HI,

If you run the script without errors it is goog news. Now cgek your path to the picture yuu may need to add an extre slash to the path. I will check it later on the linux because I run script on the windows

"file:///home/ollie/Desktop/Screenshot.png"
0
 

Author Comment

by:opike
ID: 34221915
Yup - it was a missing slash. That makes it tough to troubleshoot when you don't get a message saying something to the effect of "file not found".

Thanks a lot for all your help - really appreciate it.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question