@@ -74,6 +74,24 @@ def upgrade_data(data, upgrade_functions, to_version, version_field="version"):
7474cell_reference = re .compile (r"\$?([A-Z]{1,3})\$?([0-9]{1,7})" )
7575
7676
77+ def zone_to_xc (zone ) -> str :
78+ top = zone ["top" ]
79+ bottom = zone ["bottom" ]
80+ left = zone ["left" ]
81+ right = zone ["right" ]
82+
83+ has_header = zone .get ("hasHeader" , False )
84+ is_one_cell = top == bottom and left == right
85+
86+ if bottom is None and right is not None :
87+ return f"{ number_to_letters (left )} :{ number_to_letters (right )} " if top == 0 and not has_header else f"{ to_xc (left , top )} :{ number_to_letters (right )} "
88+ elif right is None and bottom is not None :
89+ return f"{ top + 1 } :{ bottom + 1 } " if left == 0 and not has_header else f"{ to_xc (left , top )} :{ bottom + 1 } "
90+ elif bottom is not None and right is not None :
91+ return to_xc (left , top ) if is_one_cell else f"{ to_xc (left , top )} :{ to_xc (right , bottom )} "
92+
93+ raise ValueError ("Bad zone format" )
94+
7795def letters_to_number (letters ):
7896 """
7997 Convert a string (describing a column) to its number value.
@@ -217,3 +235,11 @@ def to_xc(col, row):
217235 'B2'
218236 """
219237 return number_to_letters (col ) + str (row + 1 )
238+
239+
240+ def overlap (z1 , z2 ) -> bool :
241+ if z1 ["bottom" ] < z2 ["top" ] or z2 ["bottom" ] < z1 ["top" ]:
242+ return False
243+ if z1 ["right" ] < z2 ["left" ] or z2 ["right" ] < z1 ["left" ]:
244+ return False
245+ return True
0 commit comments