: Regarding xlwt style num_format_str

841 views
Skip to first unread message

shardul Chokshi

unread,
Jul 26, 2010, 11:54:47 AM7/26/10
to python-excel
hi !

Here is my code.

I want to change format of cell which is float 1.2345E+11 to number
123450000 , just an example.

As excel messes up with data types here.

I made a new style XFStyle Object.

Here is my code:--

open workbook:---
style = XFStyle()
decimal_style = easyxf(num_format_str = '0')
print dir(style)
style.num_format_str = "Special"
newbook = Workbook(encoding = 'utf-8')

sheet1 = newbook.add_sheet('Sheet100')

sheet1.set_style = Styles(book)

sheet1.write(2,0,1.23457E+11,decimal_style)

newbook.save('unicode.xls')


When i open my unicode.xls I see ####### instead of number

Where I am doing wrong ?

Help will be greatly appreciated !

Regards,
shardul

Michael Jugovich

unread,
Jul 26, 2010, 12:00:35 PM7/26/10
to python...@googlegroups.com
when you click on the cell what do you see in the formula window? Try clicking on the cell and pressing F2. When the column width is smaller then the number length excel displays #### instead of the number.


--
You received this message because you are subscribed to the Google Groups "python-excel" group.
To post to this group, send an email to python...@googlegroups.com.
To unsubscribe from this group, send email to python-excel...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/python-excel?hl=en-GB.


John Machin

unread,
Jul 26, 2010, 7:59:25 PM7/26/10
to python...@googlegroups.com
On 27/07/2010 1:54 AM, shardul Chokshi wrote:
> hi !
>
> Here is my code.
>
> I want to change format of cell which is float 1.2345E+11 to number
> 123450000 , just an example.
>
> As excel messes up with data types here.

What does that mean?

>
> I made a new style XFStyle Object.
>
> Here is my code:--
>
> open workbook:---
> style = XFStyle()
> decimal_style = easyxf(num_format_str = '0')
> print dir(style)
> style.num_format_str = "Special"
> newbook = Workbook(encoding = 'utf-8')
>
> sheet1 = newbook.add_sheet('Sheet100')
>
> sheet1.set_style = Styles(book)

"book" isn't defined. Apart from that, what are you trying to accomplish
with that statement??

> sheet1.write(2,0,1.23457E+11,decimal_style)
>
> newbook.save('unicode.xls')
>
>
> When i open my unicode.xls I see ####### instead of number

The column is too narrow to display the number, so Excel displays #####.
To fix one column (e.g. column E) : double click on the little vertical
bar between E and F in the column header bar [does auto-fit] OR grab the
little bar and drag it to the right.

To answer a possible next question: It is not possible to use xlwt to do
auto-fit. It is possible to do a rough calculation and set the column
width accordingly. Search the google-group archive for sample code.


Reply all
Reply to author
Forward
0 new messages