【问题标题】:Python libreoffice set margin values, optimal height and print document with unoPython libreoffice 使用 uno 设置边距值、最佳高度和打印文档
【发布时间】:2017-12-10 08:34:02
【问题描述】:

我尝试使用集成在 Libreoffice 安装中的 Python 与 libreoffice 进行交互。而且我在任何地方都找不到如何在 PageStyle 中设置边距,以设置最佳行高并打印几份文档。或者,也许,我可以在 Libreoffice 中编写宏并从 python 运行它。下面的代码不起作用。

pageStyle = document.getStyleFamilies().getByName("PageStyles")
page = pageStyle.getByName("Default")
page.LeftMargin = 500

附:对不起我的英语。

【问题讨论】:

  • 尝试更具体地说明您要实现的目标
  • 一开始我想设置边距。
  • 什么操作系统?
  • 操作系统是Windows。

标签: python libreoffice uno


【解决方案1】:

在大多数版本的 LibreOffice 中,默认样式的名称是“默认样式”。在 Apache OpenOffice 中,它被命名为“默认”。

这是完整的代码。例如,将文件命名为change_settings.py

import uno

def set_page_style_margins():
    document = XSCRIPTCONTEXT.getDocument()
    pageStyle = document.getStyleFamilies().getByName("PageStyles")
    page = pageStyle.getByName("Default Style")
    page.LeftMargin = 500

g_exportedScripts = set_page_style_margins,

在我的 Windows 10 系统上,此脚本位于目录 C:\Users\<your username>\AppData\Roaming\LibreOffice\4\user\Scripts\python 下。您需要创建最后两个目录,并且大小写必须匹配。

现在,在 LibreOffice Writer 中,转到 工具 -> 宏 -> 运行宏。 展开到 我的宏 -> change_settings 并选择宏名称 set_page_style_margins

有关使用 LibreOffice 的 Python 的完整介绍:

【讨论】:

    猜你喜欢
    • 2014-02-05
    • 1970-01-01
    • 1970-01-01
    • 2016-09-06
    • 2011-05-24
    • 1970-01-01
    • 1970-01-01
    • 2016-03-10
    • 2014-02-15
    相关资源
    最近更新 更多