Problem with Formula in Python script for LibreOffice Calc

Viewed 109

I'm starting work with LibreOffice Calc instead of Excel for my new job. I was (kind of) used to program in VBA. But, as I have to change programs, I want to change the language too. I have a Python basic notion, but I am having some difficulties.

Objective

I want to write a formula by a macro and see the result.

#!/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

Intended Result: enter image description here

Aquaired Result: enter image description here

I also tried change 'sheetForm.getCellRangeByName(location).setString(information)' for 'sheetForm.getCellRangeByName(location).setFormula(information)', but the result is bad too: enter image description here

Information:

  • =HOJE() is the same of =TODAY(), but in Portuguese.
  • #NOME? is the same of #NAME?
  • LibreOffice Version: 7.1.4.2 (x64) / LibreOffice Community

Another question: Where can I find some (good) documentation of commands and functions to write Python scripts for LibreOffice Calc?

Best regards!

0 Answers
Related