微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

LibreOffice Calc 的 Python 脚本中的公式问题

如何解决LibreOffice Calc 的 Python 脚本中的公式问题

我的新工作开始使用 LibreOffice Calc 而不是 Excel。我曾经(有点)习惯用 VBA 编程。但是,由于我必须更改程序,因此我也想更改语言。我有 Python 的基本概念,但遇到了一些困难。

目标

我想用宏写一个公式,看看结果。

#!/bin/python3

#Script usado no programa Form_Atendimento.ods

#Cria objeto document,referenciando o documento aberto
document = XSCRIPTCONTEXT.getDocument()

#Cria objeto sheets,referenciando as planilhas
sheets = document.getSheets()

#Função que configura os parâmetros para que seja escrita a função =HOJE
def write_today():
    
    information = '=HOJE()'
    sheet = 'Form'
    location = 'B5'
    write_function(information,sheet,location)
    
    return 0

#Função que escreve qualquer função
def write_function(information,location):

    sheetForm = sheets.getByName(sheet)
    sheetForm.getCellRangeByName(location).setString(information)
    
    
    
    return 0

预期结果:

enter image description here

结果:

enter image description here

我也尝试将 'sheetForm.getCellRangeByName(location).setString(information)' 更改为 'sheetForm.getCellRangeByName(location).setFormula(information)',但结果也很糟糕:

enter image description here

信息:

  • =HOJE() 与 =TODAY() 相同,但使用的是葡萄牙语。
  • #NOME?与#NAME 相同吗?
  • LibreOffice 版本:7.1.4.2 (x64) / LibreOffice 社区

一个问题: 我在哪里可以找到一些(优秀的)命令和函数文档来为 LibreOffice Calc 编写 Python 脚本?

最好的问候!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。