I modified xlwt-0.7.2 to support adding custom RGB colors in the b8 palette.
I hope that this code can be used by other people now, and will be in the next release of xlwt.
From the user perspective, I added 2 new routines.
xlwt.add_palette_colour(colour_str, array_index)
set_colourRGB (self, colour_str, array_index, redVal, greenVal, BlueVal)
If no new colors are added, then xlwt behaves the same as today and no color palette is written to the .xls file.
If any new colors are added, then the custom b8 color palette is written to the .xls file.
Sample code is:
xlwt.add_palette_colour("light_blue_21", 0x21)
wbi = xlwt.Workbook()
wbi.set_colourRGB("light_blue_21", 0x21, 197, 217, 241) # 0xF1D9C5 in excel palette location 0x21
wsi = wbi.add_sheet('Roadmap')
style_n_r_L_green_wrap = ezxf('pattern: pattern solid, fore_colour light_blue_21;' 'align: horiz right, wrap yes;' "borders: left double;")
wsi.write(11, 0, "Dual Risk Rating:", style_n_r_L_green_wrap)
The modifications to xlwt-0.7.2 include one new file
Colors.py
and changes to 3 other files
BIFFRecords.py
Style.py
Workbook.py
The diffs for the 3 modified files are in diff.log, and all 4 files are in the folder NEW_FILES.
I haven't tried out your changes yet, but assuming they work, I like
the additional functionality! Thanks for the contribution!
John Y.
Hi,I modified xlwt-0.7.2 to support adding custom RGB colors in the b8 palette.
I hope that this code can be used by other people now, and will be in the next release of xlwt.
From the user perspective, I added 2 new routines.
xlwt.add_palette_colour(colour_str, array_index)
set_colourRGB (self, colour_str, array_index, redVal, greenVal, BlueVal)
If no new colors are added, then xlwt behaves the same as today and no color palette is written to the .xls file.
If any new colors are added, then the custom b8 color palette is written to the .xls file.Sample code is:
xlwt.add_palette_colour("light_blue_21", 0x21)
wbi = xlwt.Workbook()
wbi.set_colourRGB("light_blue_21", 0x21, 197, 217, 241) # 0xF1D9C5 in excel palette location 0x21
wsi = wbi.add_sheet('Roadmap')
style_n_r_L_green_wrap = ezxf('pattern: pattern solid, fore_colour light_blue_21;' 'align: horiz right, wrap yes;' "borders: left double;")
Right now the diffs are backwards (I can't apply them with the patch
command). Can you make new diffs, but make sure your are diffing old
against new, and use the -u flag? Possibly put them all together, but
do the diffs from the root of the source tree (or one level up) so they
can easily be applied with patch -p0 or patch -p1.
Also I if you use the "-N" flag then you can diff a nonexistent old file
with the new file and the patch will automatically create the file.
I normally do this kind of thing that creates a patch that will apply
with patch -p1:
diff -i -N path.orig/to/file1 /path/to/file1 > my.patch
diff -i -N path.orig/to/file2 /path/to/file2 >> my.patch
diff -i -N path.orig/to/nonexistent /path/to/newfile >> my.patch
Too bad python-excel doesn't have a subversion or git repository as you
can generate complete diffs with a simple "svn diff" or "git diff"
https://secure.simplistix.co.uk/svn/xlwt/
https://secure.simplistix.co.uk/svn/xlrd/
https://secure.simplistix.co.uk/svn/xlutils/
Chris
--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
I cleaned up the code, based on John Machin's comments, and added correct patch files.
Note that the global routine add_palette_colour() allows defining ezxf() shortcuts before the Workbook is instantiated.
Otherwise, there is no need to call add_palette_colour().A better piece of sample code is:file1.pyxlwt.add_palette_colour("light_blue_21", 0x21)style_n_r_L_green_wrap = ezxf('pattern: pattern solid, fore_colour light_blue_21;' 'align: horiz right, wrap yes;' "borders: left double;")file2.py
wbi = xlwt.Workbook()
wbi.set_colourRGB("light_blue_21", 0x21, 197, 217, 241) # 0xF1D9C5 in excel palette location 0x21
wsi = wbi.add_sheet('Roadmap')
wsi.write(11, 0, "Dual Risk Rating:", style_n_r_L_green_wrap)
Has anyone used the new code,
are there any comments on it?
John, have you added this code to the SVN main trunk?