xlwt 0.7.4: MS Excel '%' and Currency format buttons do no work on xlwt created spreadsheets.

238 views
Skip to first unread message

Walter Prins

unread,
Jun 21, 2012, 6:03:33 AM6/21/12
to python...@googlegroups.com
Hello,

I've found an issue (actually quite some time ago already) whereby
spreadsheets written by xlwt has the peculiar defect that the
quickformat buttons ('%', currency and number) on the toolbar (or the
Home Ribbon in Excel 2007 and 2010) do not work when you try to
quickformat a cell. When you attempt to do so for example by clicking
on the percent button after having selected a cell with a number in
it, you get the error message from Excel: 'Style "Percent' not found.'
Similarly for the currency button: 'Style "Currency" not found." and
the number (comma) button 'Style "Comma" not found.'

The issue can be worked around by doing the formatting by going the
"long route", e.g. right-clicking the cell, clicking "Format Cells"
and then clicking "Percentage" in the list etc. (I notice that
"Percentage" != "Percent", not sure if that's coincidental or not.)

Anyway, it's not exactly a massive problem but I was nevertheless
wondering whether it's a bug and should be reported as such? The
problem doesn't exist obviously with workbooks created by Excel
itself, which suggests there's something peculiar about the xlwt
created workbook that causes Excel to behave in this way.

To reproduce:
1) Install Excel 2003, 2007 or 2010 (tested to be present on all 3)
2) Install Python 2.7 (2.7.2 used in my last test)
2) Install xlwt 0.7.4 (presumably this problem may exists with other
versions but this hasn't been tested.)
3) Run the following Python program snippet:

import xlwt
xlwb = xlwt.Workbook()
xlws = xlwb.add_sheet('sheet1', True)
xlws.write(1,1,0.01)
xlwb.save('test.xls')

4) Open up the file test.xls in Excel
5) Click on cell 1,1 containing the value 0.01
6) Click on the "%" button to try and manually format the cell as a perecentage
7a) What actually happens: The message "Style 'Percent' not found." is
displayed.
7b) What should happen: Excel should allow reformatting the cell as a
percentage.

Thanks in advance,

Walter

Tim White

unread,
Jun 21, 2012, 11:25:14 AM6/21/12
to python...@googlegroups.com
-----Original Message-----
On Thursday, June 21, 2012 6:04 AM Walter Prins wrote
Hope this helps...

When I open a new blank worksheet in Excel 2007 the custom styles
include (from the Home ribbon, Styles) the Number Format styles "Comma,
Comma[0], Currency, Currency[0], Percent". These are missing from the
xlwt 0.7.4 created 'test.xls' you described (although all of the other
custom styles are present).
If I add a 'percent' Custom Styles Number Format that is set to the
"Percentage" format in the Format Cells dialog then using the '%'
quickformat button works without complaint. Note: the case of 'percent'
is different to the 'Percent' Excel complains about being missing - so
case doesn't seem to matter.
Don't know why the other custom styles would be present but all of the
Number Format styles would be missing.
Possibly the Number Format styles are part of the default blank
worksheet that Excel uses when the user asks for a new worksheet.
If I merge the styles from a freshly opened blank worksheet into the
'test.xls' file it grows from 5,632 bytes to 17,408 bytes! (probably
because all the other quickformat button styles are added as well).

This seems like an Excel customization feature that almost everyone
gets by default so looks like a 'standard' but would be wrong to build
into every xlwt created sheet because it is really user optional and
could be wrong for (a possibly very small) set of users.

If you are likely to use the "%" and other quickformat buttons more than
once per worksheet it might be slightly less inconvenient to merge the
custom styles from a blank worksheet. You could even create a macro to
do the merge with one click.

Tim White


This e-mail message may contain client privileged and/or confidential information, and is intended only for the use of the individual or entity named above. Any unauthorized use, dissemination or copying is strictly prohibited. If you have received this communication in error, please notify us immediately by reply e-mail and delete or discard this message.

Chris Withers

unread,
Jun 22, 2012, 2:22:44 PM6/22/12
to python...@googlegroups.com, Walter Prins
On 21/06/2012 11:03, Walter Prins wrote:
> Anyway, it's not exactly a massive problem but I was nevertheless
> wondering whether it's a bug and should be reported as such?

It's certainly worth reporting in the xlwt tracker on GitHub so it
doesn't get lost in the mailing list churn...

> To reproduce:
<snip excellent steps>
> 6) Click on the "%" button to try and manually format the cell as a perecentage
> 7a) What actually happens: The message "Style 'Percent' not found." is
> displayed.
> 7b) What should happen: Excel should allow reformatting the cell as a
> percentage.

The steps above would be great to go in an issue on the tracker.
Also, *please* add an equivalent .xls file created with Excel itself
that behaves as you'd expect!

cheers,

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk

Walter Prins

unread,
Jun 22, 2012, 6:30:13 PM6/22/12
to python...@googlegroups.com
Chris,

On 22 June 2012 19:22, Chris Withers <ch...@simplistix.co.uk> wrote:
> The steps above would be great to go in an issue on the tracker.
> Also, *please* add an equivalent .xls file created with Excel itself that
> behaves as you'd expect!

I've reported the issue as requested and included Tim's comments also.
I must however be missing the obvious as I've not been able to add the
equivalent Excel reference file -- how/where exactly do you attach
files against a submitted issue?

Thanks :)


Walter

Chris Withers

unread,
Jun 29, 2012, 2:27:43 PM6/29/12
to python...@googlegroups.com, Walter Prins
On 22/06/2012 23:30, Walter Prins wrote:
> I've reported the issue as requested and included Tim's comments also.
> I must however be missing the obvious as I've not been able to add the
> equivalent Excel reference file -- how/where exactly do you attach
> files against a submitted issue?

Wow, yes, I can't see anything either...

Perhaps you could raise this with the good folks at GitHub and let us
know what you find?

cheers.

Adrian Klaver

unread,
Jun 29, 2012, 3:03:44 PM6/29/12
to python...@googlegroups.com
On 06/29/2012 11:27 AM, Chris Withers wrote:
> On 22/06/2012 23:30, Walter Prins wrote:
>> I've reported the issue as requested and included Tim's comments also.
>> I must however be missing the obvious as I've not been able to add the
>> equivalent Excel reference file -- how/where exactly do you attach
>> files against a submitted issue?
>
> Wow, yes, I can't see anything either...
>
> Perhaps you could raise this with the good folks at GitHub and let us
> know what you find?

Was following along. The only thing I could find is:

http://stackoverflow.com/questions/10963205/how-to-attach-file-to-a-github-issue

>
> cheers.
>
> Chris
>


--
Adrian Klaver
adrian...@gmail.com


Chris Withers

unread,
Jun 30, 2012, 6:11:37 AM6/30/12
to python...@googlegroups.com, Adrian Klaver
On 29/06/2012 20:03, Adrian Klaver wrote:
>> Perhaps you could raise this with the good folks at GitHub and let us
>> know what you find?
>
> Was following along. The only thing I could find is:
>
> http://stackoverflow.com/questions/10963205/how-to-attach-file-to-a-github-issue

Surprisingly confirmed by the guys at GitHub:

> ==================================================
> From: Ryan Waldron (GitHub Staff)
> Subject: How do I attach files to an issue in a GitHub issue tracker?
>
> Hi, Chris! You can't attach files directly to issues in the issue tracker. You can upload files to some publicly-accessible site (Dropbox, etc.) and link to it.
>
> Hope this helps!

cheers,
Reply all
Reply to author
Forward
0 new messages