def xlformat_factory(format):
 key = hash(format)
 fmt_ = xlformat_factory.created_formats.get(key)
 if (fmt_ is not None):
  return fmt_
 format = copy.deepcopy(format)
 xlstyle = excel.XFStyle()
 if isinstance(format, mlab.FormatPercent):
  zeros = u''.join(([u'0'] * format.precision))
  xlstyle.num_format_str = (u'0.%s%%;[RED]-0.%s%%' % (zeros, zeros))
  format.scale = 1.0
 elif isinstance(format, mlab.FormatFloat):
  if (format.precision > 0):
   zeros = u''.join(([u'0'] * format.precision))
   xlstyle.num_format_str = (u'#,##0.%s;[RED]-#,##0.%s' % (zeros, zeros))
  else:
   xlstyle.num_format_str = u'#,##;[RED]-#,##'
 elif isinstance(format, mlab.FormatInt):
  xlstyle.num_format_str = u'#,##;[RED]-#,##'
 else:
  xlstyle = None
 format.xlstyle = xlstyle
 xlformat_factory.created_formats[key] = format
 return format

def xlformat_factory ( format ) : key = hash ( format ) fmt_ = xlformat_factory . created_formats . get ( key ) if ( fmt_ is not None ) : return fmt_ format = copy . deepcopy ( format ) xlstyle = excel . XFStyle ( ) if isinstance ( format , mlab . FormatPercent ) : zeros = u'' . join ( ( [ u'0' ] * format . precision ) ) xlstyle . num_format_str = ( u'0.%s%%;[RED]-0.%s%%' % ( zeros , zeros ) ) format . scale = 1.0 elif isinstance ( format , mlab . FormatFloat ) : if ( format . precision > 0 ) : zeros = u'' . join ( ( [ u'0' ] * format . precision ) ) xlstyle . num_format_str = ( u'#,##0.%s;[RED]-#,##0.%s' % ( zeros , zeros ) ) else : xlstyle . num_format_str = u'#,##;[RED]-#,##' elif isinstance ( format , mlab . FormatInt ) : xlstyle . num_format_str = u'#,##;[RED]-#,##' else : xlstyle = None format . xlstyle = xlstyle xlformat_factory . created_formats [ key ] = format return format
copy the format .