Python Libre Office Uno:实例化com.sun.star.drawing.LineStyle.SOLID?

时间:2019-01-15 10:33:55

标签: python libreoffice uno

在Ubuntu 18.04上使用LibreOffice 6.0.7.3 00m0(Build:3),想要在LibreOffice Draw中使用Python宏:

import uno
import unohelper
#import com.sun.star.drawing #No module named 'com'
#from com.sun.star.lang import XServiceName # passes
#from com.sun.star.drawing import LineStyle # : No module named 'com' (or 'com.sun.star.drawing.LineStyle' is unknown)
#from com.sun.star import drawing # No module named 'com' (or 'com.sun.star.drawing' is unknown)

def myfunc():
  ...
  oCtx = uno.getComponentContext()
  oServiceManager = oCtx.ServiceManager

  oDoc = XSCRIPTCONTEXT.getDocument()
  oSlideList = oDoc.getDrawPages()
  ...

  #drawObject.LineStyle = com.sun.star.drawing.LineStyle.SOLID # name 'com' is not defined
  #drawObject.LineStyle = uno.createUnoStruct("com.sun.star.drawing.LineStyle.SOLID") # pyuno.getClass: uno exception com.sun.star.drawing.LineStyle.SOLID is unknown
  #drawObject.LineStyle = uno.createUnoStruct("com.sun.star.drawing.LineStyle") # pyuno.getClass: com.sun.star.drawing.LineStyleis a ENUM, expected EXCEPTION, STRUCT or INTERFACE
  #drawObject.LineStyle = oServiceManager.createInstance('com.sun.star.drawing.LineStyle') # TYPE is not supported!
  drawObject.LineStyle = oServiceManager.createInstance('com.sun.star.drawing.LineStyle.SOLID') # TYPE is not supported!

...但我根本无法实例化com.sun.star.drawing.LineStyle.SOLID。如何在Python宏中实例化它?

1 个答案:

答案 0 :(得分:0)

在这里找到它:https://docs.libreoffice.org/librelogo/html/LibreLogo_8py_source.html

from com.sun.star.drawing.LineStyle import SOLID # passes

def myfunc():
  ...
  drawObject.LineStyle = SOLID