Gerry wrote: > I'd like to word wrap some cells, but not others, in an Excel > spreadsheet, using pyExcelerator and Excel 2003, SP1, under XP. > > The code below creates the spreadsheet, but both cells are > word-wrapped. > > As far as I can tell, the second call to XFStyle() overwrites a GLOBAL > wrap setting, and affects even cells written before the call to > XFStyle.
You are mostly correct. In Style.py, each style gets initialised to refer to a module-global bunch of default objects. No copying is done. Have a look at the patched code down the bottom of this posting -- it appears to work. > > Can anyone shed any light? > > Thanks, > > Gerry > > ============================ > from pyExcelerator import * > > > w = Workbook() > ws = w.add_sheet("alpha") > > style = XFStyle() > style.alignment.wrap = Alignment.NOT_WRAP_AT_RIGHT > ws.write(1,1,"Not wrapped" + "-" * 50, style) > > style2 = XFStyle() > style2.alignment.wrap = Alignment.WRAP_AT_RIGHT > ws.write(2,1,"Wrapped" + "-" * 50, style2) > > w.save("test.xls") if 0: # original _default_num_format = 'general' _default_font = Formatting.Font() _default_alignment = Formatting.Alignment() _default_borders = Formatting.Borders() _default_pattern = Formatting.Pattern() _default_protection = Formatting.Protection() class XFStyle(object): def __init__(self): self.num_format_str = _default_num_format self.font = _default_font self.alignment = _default_alignment self.borders = _default_borders self.pattern = _default_pattern self.protection = _default_protection else: # patch class XFStyle(object): def __init__(self): self.num_format_str = 'general' self.font = Formatting.Font() self.alignment = Formatting.Alignment() self.borders = Formatting.Borders() self.pattern = Formatting.Pattern() self.protection = Formatting.Protection() If this works for you, you might like to submit a patch to http://sourceforge.net/tracker/?func=browse&group_id=134081&atid=730645 HTH, John -- http://mail.python.org/mailman/listinfo/python-list