用于LibreOffice Calc的Python脚本中的公式存在问题

2024-05-23 17:52:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我开始用libreofficecalc而不是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, sheet, 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()相同,但用葡萄牙语
  • #诺姆?名字是一样的吗
  • 图书馆办公室版本:7.1.4.2(x64)/图书馆办公室社区

另一个问题: 在哪里可以找到一些(好的)命令和函数文档,用于为libreofficecalc编写Python脚本

致以最良好的祝愿


Tags: forminformationlocationdocumentwritesheetquesheets