@@ -413,17 +413,19 @@ def do_unflatten(self):
413413 )
414414
415415 def inthere (unflattened , id_name ):
416- if self .xml :
416+ if self .xml and not isinstance (unflattened .get (self .id_name ), Cell ):
417+ # For an XML tag
417418 return unflattened [id_name ]["text()" ].cell_value
418419 else :
420+ # For a JSON, or an XML attribute
419421 return unflattened [id_name ].cell_value
420422
421423 if (
422424 self .id_name in unflattened
423425 and inthere (unflattened , self .id_name )
424426 in main_sheet_by_ocid [root_id_or_none ]
425427 ):
426- if self .xml :
428+ if self .xml and not isinstance ( unflattened . get ( self . id_name ), Cell ) :
427429 unflattened_id = unflattened .get (self .id_name )[
428430 "text()"
429431 ].cell_value
@@ -752,7 +754,11 @@ def get_sheet_lines(self, sheet_name):
752754 if not header :
753755 # None means that the cell will be ignored
754756 value = None
755- elif sheet_configuration .get ("hashcomments" ) and header .startswith ("#" ):
757+ elif (
758+ sheet_configuration .get ("hashcomments" )
759+ and isinstance (header , str )
760+ and header .startswith ("#" )
761+ ):
756762 # None means that the cell will be ignored
757763 value = None
758764 output_row [header ] = value
@@ -945,7 +951,7 @@ def unflatten_main_with_parser(parser, line, timezone, xml, id_name):
945951 # Quick solution to avoid casting of date as datetinme in spreadsheet > xml
946952 if xml :
947953 if type (cell .cell_value ) == datetime .datetime and not next_path_item :
948- if "datetime" not in path :
954+ if "datetime" not in str ( path ) :
949955 current_type = "date"
950956
951957 ## Array
@@ -1116,7 +1122,11 @@ def __repr__(self):
11161122 def append (self , item ):
11171123 if self .keyfield in item :
11181124 if self .xml :
1119- if isinstance (item [self .keyfield ]["text()" ], Cell ):
1125+ if isinstance (item [self .keyfield ], Cell ):
1126+ # For an XML attribute
1127+ key = item [self .keyfield ].cell_value
1128+ elif isinstance (item [self .keyfield ]["text()" ], Cell ):
1129+ # For an XML tag
11201130 key = item [self .keyfield ]["text()" ].cell_value
11211131 else :
11221132 key = item [self .keyfield ]["text()" ]
0 commit comments