【发布时间】:2016-04-25 23:08:17
【问题描述】:
关于如何使用 Python 控制 LibreOffice 文本文档和电子表格的示例很多,但关于如何使用绘图程序的文档却很少。我试图弄清楚如何使用 Python 在 LibreOffice 中绘制流程图或至少一些形状。我使用的是 Windows 10 和 LibreOffice 5 附带的 Python 3.3。
有一个很好的例子说明如何使用电子表格LibreOffice Python example
在示例中,如果您使用文本文档、电子表格、绘图或其他文档,以下行很常见。
import socket
import uno
localContext = uno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext )
ctx = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" )
smgr = ctx.ServiceManager
desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx)
model = desktop.getCurrentComponent()
以下代码也在示例中用于修改电子表格程序,效果很好。该代码将“Hello World”和一个数字放入电子表格中。
cell1 = active_sheet.getCellRangeByName("C4")
cell1.String = "Hello world"
cell2 = active_sheet.getCellRangeByName("E6")
cell2.Value = cell2.Value + 1
对于绘图程序,是否有一些类似的命令可以获取活动工作表并获取可以绘制的形状列表?我可能找错地方了,但没有找到绘图程序的任何文档。
【问题讨论】:
标签: python libreoffice flowchart