1
Hello, I’m trying to use worksheet.write_formula(row,col+5,'=B%d-E1'%(row+1))
to write a formula in CALC, but the minus sign seems to be misinterpreted in Libreoffice and it is necessary that I manually change the sign. You would know how to solve this problem?
The complete code is this:
from pyexcel_ods import save_data
import time, sys
import xlsxwriter
import serial
receivedSF = serial.Serial('/dev/ttyUSB0', 9600)
row = 0
col = 0
count = input("Numero de dados a ser coletados: ")
workbook = xlsxwriter.Workbook('hello.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write(0,3,"TEMPO DE REFERENCIA:")
worksheet.write(0,4,time.time())
for item in range(count):
valor = int(receivedSF.read(2))
print row, valor
worksheet.write(row,col, valor)
worksheet.write(row,col+1,time.time())
worksheet.write_formula(row,col+5,'=B%d-E1'%(row+1))
row+=1
workbook.close()
receivedSF.close()
Could you describe the "change manually" ?
– Trevud0
You can put the versions of xlsxwriter, libreoffice, Python you are using (
xlsxswriter.__version__
contains the version). And also which operating system? I tested writing a formula with "-" on Linux, with Python 3.6 and xlsxwriter 0.9.8 and it worked perfectly.– jsbueno
A suggestion -use
xlsxwriter.write_formula(XXX, YYY, "=%f" % time.time() )
and also for the value - instead of.write(...)
- the reason is that thewrite
as only writes the text of cells may be subject to the differences between "." and "," as a separator for decimals, if your libreoffice is in Portuguese. With the "writeformula", libreoffice should understand content as numerical independent of formatting. "-".– jsbueno
Jsbueno thanks for the return: the versions are Python 2.7.12; xlsxswriter 0.9.8; Ubuntu 16.04 LTS. The problem is not the interpretation of "," because when I change the "-" signal manually it does the operation normally.
– Taidson
I think it might be some incompatibility with encoding since programming languages use ASCII, only I don’t know how to check this.
– Taidson
I did a gambiarra, 'Workbook = xlsxwriter. Workbook('hello.xlsx')' in this snippet of the code is generated a file with the extension . xlsx what I did was create a copy of this file with the . ods extension and the spreadsheet started working properly. But I still don’t know how to solve the problem directly in python.
– Taidson
why are you not using Python 3.6? Python 2.7 is from 2010 - and will go off-line in another 3 years. Ubuntu just install the package "python3" call your program with "python3" (if you’re not using virtualenv - what you should be) . You didn’t put the libreoffice version - squat to ask - but it seems to be the problem Here is 5.2.7.2
– jsbueno
I actually have Python 2.7 and 3.5 but since I’m starting in Python I preferred to use the 2.7 that was already in Ubuntu, since when I wrote the code I used some things incompatible with Python 3.5. And the libreoffice version is 5.1.6.2.
– Taidson