Error with incorrect or incomplete graph

Issue #892 duplicate
Augustin Cisterne-Kaas
created an issue

Hi,

Using the version 2.5.0a3 I got an issue when loading a workbook with a graph that is incorrect or incomplete. The aim was for the graph series and axis to be dynamically loaded (CF: Screenshot). Instead of adding normal values, I wrote a variable that will be converted later on thanks to this library.

However when you try to load an excel file with the following code:

wb = openpyxl.load_workbook(XLSX_TEMPLATE_PATH)

You will get the following error:

lib/python2.7/site-packages/openpyxl/descriptors/base.py", line 59, in _convert
raise TypeError('expected ' + str(expected_type))
TypeError: expected <type 'float'>

The library is trying to read the graph but since it can't, an exception is raised.
I am not sure how it should be solved so I made a quick monkey patch that works for my case.

import openpyxl
# Patch to make graph works with none value or variables
# openpyxl version 2.5.0a3
def _convert(expected_type, value):
    """
    Check value is of or can be converted to expected type.
    """
    if not isinstance(value, expected_type):
        try:
            value = expected_type(value)
        except:
            value = 0.0
            # raise TypeError('expected ' + str(expected_type))
    return value

openpyxl.descriptors.base._convert = _convert

I am sure that setting the value to 0.0 ain't the solution cause there are a lot more parameters that I am not aware of that need to be taken into account. Not being able to add some custom variables that your application can deal with later looks like an issue to me.

Cheers,

Augustin