在python中通过UNO访问LibreOffice/OpenOffice,经常需要用到命令、Filter。因为LibreOffice/OpenOffice在线分档非常庞大,我找了好长时间才找到,记下来,方便后续查阅。
例如,下面的代码片段,用到了命令UpdateAllIndexes、SaveAs、ExportDirectToPDF:
dispatcher.executeDispatch(doc, ".uno:UpdateAllIndexes", "", 0, ())
dispatcher.executeDispatch(doc, ".uno:SaveAs", "", 0, tuple(opts))
dispatcher.executeDispatch(doc, ".uno:ExportDirectToPDF", "", 0, tuple([struct, struct2]))
要知道有些命令可以使用,请查阅命令列表:https://wiki.openoffice.org/wiki/Framework/Article/OpenOffice.org_3.x_Commands
例如,下面的代码片段用到了Filter:“MS Word 2007 XML”、“writer_pdf_Export”
struct = uno.createUnoStruct("com.sun.star.beans.PropertyValue")
struct.Name = "FilterName"
struct.Value = "MS Word 2007 XML"
struct2 = uno.createUnoStruct('com.sun.star.beans.PropertyValue')
struct2.Name = "FilterName"
struct2.Value = "writer_pdf_Export"
要知道有哪些Filter可以使用,请查阅Filter列表:https://wiki.openoffice.org/wiki/Framework/Article/Filter/FilterList_OOo_3_0
https://help.libreoffice.org/latest/en-US/text/shared/guide/convertfilters.html