Reputation: 21
First time making a question here. I am learning Python and I've encountered a problem with my last code. For reference, I'm using the 3.6 version and everything was installed in the last weeks, so should be updated.
When I try to open an .xlsm file with Openpyxl I get the error pasted bellow. After removing the Conditional Formatting from the workbook, everything works as expected. It also worked when using Pandas.
I have used the module with other files before without a problem. I've found a few similar questions but usually much older and supposedly corrected in older patches. The code snippet should just build the file path and worked with other files. Any lights on this?
import openpyxl
Ano = '-2018'
arquivo = 'Controle de Produção v2 '
arquivo = arquivo + dataEx[3:]+ '-' + Ano[3:]
wb = openpyxl.load_workbook("C:\\Users\\Desktop\\Dropbox\\Produção Equipes\\"+arquivo+".xlsx")
Traceback (most recent call last): File "C:\Users\Desktop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\openpyxl\descriptors\base.py", line 57, in _convert
value = expected_type(value) ValueError: could not convert string to float: '$G$16-0.015'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Users\Desktop\Documents\Hugo\Python\Projetos\Produtividade\Produtividade.py", line 33, in <module>
wb = openpyxl.load_workbook("C:\\Users\\Desktop\\Dropbox\\Produção Equipes\\"+arquivo+".xlsx", False, True) #DEFINIR CAMINHO COMPLETO File "C:\Users\Desktop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\openpyxl\reader\excel.py", line 245, in load_workbook
ws_parser.parse() File "C:\Users\Desktop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\openpyxl\reader\worksheet.py", line 127, in parse
dispatcher[tag_name](element) File "C:\Users\Desktop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\openpyxl\reader\worksheet.py", line 286, in parser_conditional_formatting
cf = ConditionalFormatting.from_tree(element) File "C:\Users\Desktop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\openpyxl\descriptors\serialisable.py", line 79, in from_tree
obj = desc.expected_type.from_tree(el) File "C:\Users\Desktop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\openpyxl\descriptors\serialisable.py", line 79, in from_tree
obj = desc.expected_type.from_tree(el) File "C:\Users\Desktop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\openpyxl\descriptors\serialisable.py", line 79, in from_tree
obj = desc.expected_type.from_tree(el) File "C:\Users\Desktop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\openpyxl\descriptors\serialisable.py", line 92, in from_tree
return cls(**attrib) File "C:\Users\Desktop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\openpyxl\formatting\rule.py", line 60, in __init__
self.val = val File "C:\Users\Desktop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\openpyxl\formatting\rule.py", line 39, in __set__
super(ValueDescriptor, self).__set__(instance, value) File "C:\Users\Desktop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\openpyxl\descriptors\base.py", line 69, in __set__
value = _convert(self.expected_type, value) File "C:\Users\Desktop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\openpyxl\descriptors\base.py", line 59, in _convert
raise TypeError('expected ' + str(expected_type)) TypeError: expected <class 'float'>
Upvotes: 1
Views: 2021
Reputation: 21
Well, not an definite answer but the program was able to fully run after commenting the lines:
def parser_conditional_formatting(self, element):
None #CHANGED FOR PRODUTIVIDADE.PY
## cf = ConditionalFormatting.from_tree(element)
## for rule in cf.rules:
## if rule.dxfId is not None:
## rule.dxf = self.differential_styles[rule.dxfId]
## self.ws.conditional_formatting.add(cf.sqref, rule)
in openpyxl\reader\worksheet.py.
I know this is not really a sollution but at least the program is loading the workbook. I will try to submit an issue in BitBucket for a better analysis.
Upvotes: 1