@@ -263,7 +263,7 @@ def get_shared_strings(self):
263
263
264
264
return self ._shared_strings
265
265
266
- def load_macro_cells (self , macrosheet , macrosheet_obj ):
266
+ def load_macro_cells (self , macrosheet , macrosheet_obj , macrosheet_names ):
267
267
strings = self .get_shared_strings ()
268
268
269
269
sheet = macrosheet_obj .xm_macrosheet if hasattr (macrosheet_obj , 'xm_macrosheet' ) else macrosheet_obj .worksheet
@@ -292,6 +292,10 @@ def load_macro_cells(self, macrosheet, macrosheet_obj):
292
292
formula_text = '=SET.NAME("{}",{})' .format (text [:first_eq_sign ], text [first_eq_sign + 1 :])
293
293
else :
294
294
formula_text = ('=' + formula .cdata ) if formula is not None else None
295
+
296
+ for name in macrosheet_names :
297
+ if name .lower () + '!' in formula_text .lower ():
298
+ formula_text = re .sub ('{}\!' .format (name ), "'{}'!" .format (name ), formula_text )
295
299
value_text = None
296
300
is_string = False
297
301
if 't' in cell_elm ._attributes and cell_elm .get_attribute ('t' ) == 's' :
@@ -379,10 +383,15 @@ def get_macrosheets(self):
379
383
if self ._macrosheets is None :
380
384
self ._macrosheets = {}
381
385
macrosheets = self .get_macrosheet_infos ()
386
+
387
+ macrosheet_names = []
388
+ for macrosheet in macrosheets :
389
+ macrosheet_names .append (macrosheet ['sheet' ].name )
390
+
382
391
for macrosheet in macrosheets :
383
392
# if the actual file exist
384
393
if macrosheet ['sheet_xml' ]:
385
- self .load_macro_cells (macrosheet ['sheet' ], macrosheet ['sheet_xml' ])
394
+ self .load_macro_cells (macrosheet ['sheet' ], macrosheet ['sheet_xml' ], macrosheet_names )
386
395
sheet = macrosheet ['sheet_xml' ].xm_macrosheet if hasattr (macrosheet ['sheet_xml' ],
387
396
'xm_macrosheet' ) else macrosheet ['sheet_xml' ].worksheet
388
397
if hasattr (sheet , 'sheetFormatPr' ):
0 commit comments