def read_named_ranges(xml_source, workbook):
 sheetnames = set((sheet.title for sheet in workbook.worksheets))
 root = fromstring(xml_source)
 for name_node in safe_iterator(root, ('{%s}definedName' % SHEET_MAIN_NS)):
  range_name = name_node.get('name')
  if DISCARDED_RANGES.match(range_name):
   warnings.warn('Discarded range with reserved name')
   continue
  node_text = name_node.text
  if external_range(node_text):
   named_range = NamedValue(range_name, node_text)
  elif refers_to_range(node_text):
   destinations = split_named_range(node_text)
   destinations = [(workbook[sheet], cells) for (sheet, cells) in destinations if (sheet in sheetnames)]
   if (not destinations):
    continue
   named_range = NamedRange(range_name, destinations)
  else:
   named_range = NamedValue(range_name, node_text)
  named_range.scope = name_node.get('localSheetId')
  (yield named_range)

def read_named_ranges ( xml_source , workbook ) : sheetnames = set ( ( sheet . title for sheet in workbook . worksheets ) ) root = fromstring ( xml_source ) for name_node in safe_iterator ( root , ( '{%s}definedName' % SHEET_MAIN_NS ) ) : range_name = name_node . get ( 'name' ) if DISCARDED_RANGES . match ( range_name ) : warnings . warn ( 'Discarded range with reserved name' ) continue node_text = name_node . text if external_range ( node_text ) : named_range = NamedValue ( range_name , node_text ) elif refers_to_range ( node_text ) : destinations = split_named_range ( node_text ) destinations = [ ( workbook [ sheet ] , cells ) for ( sheet , cells ) in destinations if ( sheet in sheetnames ) ] if ( not destinations ) : continue named_range = NamedRange ( range_name , destinations ) else : named_range = NamedValue ( range_name , node_text ) named_range . scope = name_node . get ( 'localSheetId' ) ( yield named_range )
read named ranges .