dave-howard / vsdx

vsdx - A python library for processing .vsdx files
BSD 3-Clause "New" or "Revised" License
67 stars 25 forks source link

Data Property value_cell=None raises an error #58

Closed johancj closed 11 months ago

johancj commented 1 year ago

Hi Dave,

The change implemented in https://github.com/dave-howard/vsdx/issues/55 added a new bug in my case. In the .csv file, I have a case where the value_cell = None. This raises an error in DataProperty.__init__(...) due to it checking value_cell.text in an if statement.

I suggest adding the following or something similar:

elif value_cell is None:
    value = None

So the start of __init__ becomes:

def __init__(self, *, xml: Element, shape: Shape):
    """init a DataProperty from a property xml element in a Shape object"""
    name = xml.attrib.get('N')
    # get Cell element for each property of DataProperty
    label_cell = xml.find(f'{namespace}Cell[@N="Label"]')
    value_cell = xml.find(f'{namespace}Cell[@N="Value"]')
    value = None

    if isinstance(value_cell, Element) and value_cell.attrib.get('V') is not None:
        value = value_cell.attrib.get('V')  # populate value from V attribute
    elif value_cell is None:
        value = None
    elif value_cell.text:
        value = value_cell.text  # populate value from element inner text

This might, however introduce new errors I haven't tough of.

Best regards, Johan Christian Jenssen

dave-howard commented 11 months ago

Hi @johancj - this should be resolved in latest release (0.5.15) now