Ñò ”tJc @ sm d Z d d k Z d d k Z d d k Z d d k i Z d d k i Z d „ Z d d d d d d „ Z d S( sÆ Some io tools for excel -- requires xlwt Example usage: import matplotlib.mlab as mlab import mpl_toolkits.exceltools as exceltools r = mlab.csv2rec('somefile.csv', checkrows=0) formatd = dict( weight = mlab.FormatFloat(2), change = mlab.FormatPercent(2), cost = mlab.FormatThousands(2), ) exceltools.rec2excel(r, 'test.xls', formatd=formatd) mlab.rec2csv(r, 'test.csv', formatd=formatd) iÿÿÿÿNc C sú t i | ƒ } t i ƒ } t | t i ƒ o9 d i d g | i ƒ } d | | f | _ d | _ n‡ t | t i ƒ oM | i d j o0 d i d g | i ƒ } d | | f | _ qí d | _ n' t | t i ƒ o d | _ n d } | | _ | S( sn copy the format, perform any overrides, and attach an xlstyle instance copied format is returned t t 0s 0.%s%%;[RED]-0.%s%%g ð?i s #,##0.%s;[RED]-#,##0.%ss #,##;[RED]-#,##N( t copyt deepcopyt excelt XFStylet isinstancet mlabt FormatPercentt joint precisiont num_format_strt scalet FormatFloatt FormatIntt Nonet xlstyle( t formatR t zeros( ( s= /usr/lib64/python2.6/site-packages/mpl_toolkits/exceltools.pyt xlformat_factory s i t NaNt Infc C sŠ t } t i | ƒ o+ | } t i ƒ } | i d ƒ } t } n | d j o t ƒ } n g } t i ƒ } t | _ t i ƒ } | | _ xž t | i i ƒ D]Š \ } } | i | } | i | ƒ } | d j o" t i i | i t i ƒ ƒ } n t | ƒ } | i | | | | | ƒ | i | ƒ qž W| d 7} t i t | i i ƒ ƒ } x| D]} xÿ | D]÷ } | | } | | } | i | ƒ } t i | ƒ o | i | | | | ƒ qet i | ƒ oK t i | ƒ } | d j o | } n d | } | i | | | | ƒ qe| i d j o | i | | | | ƒ qe| i | | | | | i ƒ qeW| d 7} qXW| o | i | ƒ n | S( sv save record array r to excel xlwt worksheet ws starting at rownum. if ws is string like, assume it is a filename and save to it start writing at rownum, colnum formatd is a dictionary mapping dtype name -> mlab.Format instances nanstr is the string that mpl will put into excel for np.nan value The next rownum after writing is returned t worksheeti i s -%sN(! t Falset cbookt is_string_likeR t Workbookt add_sheett TrueR t dictt Fontt boldR t fontt enumeratet dtypet namest getR t defaultformatdt typet FormatObjR t writet appendt npt aranget lent tovalt safe_isnant safe_isinft signR t save( t rt wst formatdt rownumt colnumt nanstrt infstrt autosavet filenamet wbt formatsR t stylehdrt it namet dtR t indt rowt valt sgnt s( ( s= /usr/lib64/python2.6/site-packages/mpl_toolkits/exceltools.pyt rec2excel<