Revision: 4629
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4629&view=rev
Author: jdh2358
Date: 2007-12-05 11:27:14 -0800 (Wed, 05 Dec 2007)
Log Message:
-----------
minor rec2excel enhancements
Modified Paths:
--------------
trunk/matplotlib/examples/loadrec.py
trunk/matplotlib/lib/matplotlib/mlab.py
Modified: trunk/matplotlib/examples/loadrec.py
===================================================================
--- trunk/matplotlib/examples/loadrec.py 2007-12-05 18:57:54 UTC (rev
4628)
+++ trunk/matplotlib/examples/loadrec.py 2007-12-05 19:27:14 UTC (rev
4629)
@@ -9,4 +9,6 @@
ax = fig.add_subplot(111)
ax.plot(a.date, a.adj_close, '-')
fig.autofmt_xdate()
+
+mlab.rec2excel(a, 'test.xls', colnum=4)
show()
Modified: trunk/matplotlib/lib/matplotlib/mlab.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/mlab.py 2007-12-05 18:57:54 UTC (rev
4628)
+++ trunk/matplotlib/lib/matplotlib/mlab.py 2007-12-05 19:27:14 UTC (rev
4629)
@@ -2367,7 +2367,7 @@
xlstyle.num_format_str = '#,##;[RED]-#,##'
elif isinstance(format, FormatPercent):
zeros = ''.join(['0']*format.precision)
- xlstyle.num_format_str = '0.%s%;[RED]-0.%s%'%(zeros, zeros)
+ xlstyle.num_format_str = '0.%s%%;[RED]-0.%s%%'%(zeros, zeros)
format.scale = 1.
else:
xlstyle = None
@@ -2376,12 +2376,14 @@
return format
- def rec2excel(r, ws, formatd=None, rownum=0):
+ def rec2excel(r, ws, formatd=None, rownum=0, colnum=0):
"""
save record array r to excel pyExcelerator 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 -> FormatXL instances
The next rownum after writing is returned
@@ -2399,6 +2401,12 @@
formatd = dict()
formats = []
+ font = excel.Font()
+ font.bold = True
+
+ stylehdr = excel.XFStyle()
+ stylehdr.font = font
+
for i, name in enumerate(r.dtype.names):
dt = r.dtype[name]
format = formatd.get(name)
@@ -2406,7 +2414,7 @@
format = defaultformatd.get(dt.type, FormatObj())
format = xlformat_factory(format)
- ws.write(rownum, i, name)
+ ws.write(rownum, colnum+i, name, stylehdr)
formats.append(format)
rownum+=1
@@ -2419,12 +2427,12 @@
format = formats[i]
val = format.toval(val)
if format.xlstyle is None:
- ws.write(rownum, i, val)
+ ws.write(rownum, colnum+i, val)
else:
if safe_isnan(val):
- ws.write(rownum, i, 'NaN')
+ ws.write(rownum, colnum+i, 'NaN')
else:
- ws.write(rownum, i, val, format.xlstyle)
+ ws.write(rownum, colnum+i, val, format.xlstyle)
rownum += 1
if autosave:
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell. From the desktop to the data center, Linux is going
mainstream. Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins