Funny how you found the above but not this:
https://secure.simplistix.co.uk/svn/xlutils/trunk/xlutils/docs/save.txt
> Does somebody see what i'm doing wrong, or what i forget and could
> explain it to me ?
I'm afraid you haven't really explained what it is that you're trying to
do...
My guess is that you want to do something like the following, which will
make John M frown, until xlwt supports writing to cells more than once:
from xlrd import open_workbook
from xlutils.save import save
wb = open_workbook(os.path.join(test_files,'testall.xls'))
sheet = wb.sheet_by_name('your sheet')
cell = sheet.cell(0,0)
sheet.put_cell(0,0,cell.ctype,'Changed',cell.xf_index)
save(wb,'new.xls')
However, if you tell us what it is that you're trying to do, we may be
able to advise of a better way.
cheers,
Chris
--
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk
None of the above is helpful given that I don't have access to any of
those spreadsheets.
It's even less helpful given that you haven't included the code you're
trying to run and don't appear to have done anything with the
suggestions I've provided.
Raphael: Not all of it, you've omitted the imports.
> def main():
> parser = OptionParser()
[big snip]
>
> s = Styles(book)
This "Styles" is evidently obtained by
from xlutils.styles import Styles
These droids are not the ones that you are looking for.
Chris, I strongly suggest that xlutils.styles get some documentation
that tells folk exactly what it does, and emphasises that an
xlutils.styles.CellStyle object corresponds to an Excel STYLE record
(which would have been better named STYLENAME or NAMEDSTYLE) whereas an
xlwt.Style.XFStyle object corresponds to an Excel XF record (which would
have better been called STYLE).
[another big snip]
>
> #Open new workbook
> NewDoc = xlwt.Workbook()
> #Add a New worksheet
> Newsheet = NewDoc.add_sheet(sheetNames[0])
>
> ##****
> CellStyle = xlwt.XFStyle()
> Cellfont = xlwt.Font()
The above two statements are redundant; the values are replaced below.
>
> for row_num, row_values in enumerate( lines ):
> for col, value in enumerate( row_values ):
> CellStyle = s[sh.cell(row_num,col)]
The meaningfully named s being of course a collection of
xlutils.styles.CellStyle objects ...
> Cellfont = book.font_list
> [CellStyle.xf.font_index]
> CellStyle.font = Cellfont
CellStyle is an xlutils.styles.CellStyle object but is being poked as
though it were an xlwt.Style.XFStyle object.
Aside: Changing the contents of an XFStyle object after it has been used
in a Worksheet.write() or similar will achieve the desired effect only
rarely and accidentally. All cells written with that object will be
formatted with the *same* bunch of values, namely what's in the object
at the time that Workbook.save() is called ... or possibly a striped
effect if you are using Sheet.flush_row_data().
> Newsheet.write( row_num, col, value,
> CellStyle )
... and Cellstyle has been given only 1 (font) of the 6 attributes
expected in an xlwt.Style.XFStyle object so (as mentioned on Raphael's
first message) it falls over with:
AttributeError: CellStyle instance has no attribute 'num_format_str'
HTH,
John
Done:
https://secure.simplistix.co.uk/svn/xlutils/trunk/xlutils/docs/styles.txt
cheers,