[Tutor] Excel

Jeff Shannon jeff@ccvcorp.com
Wed, 26 Jun 2002 10:09:30 -0700


Terje Johan Abrahamsen wrote:

> Then I type:
> >>>ffac.xl.Columns(5).Style.NumberFormat = "##.##"
> >>>ffac.xl.Columns(5).Style.NumberFormat
> u'$00.00'
>
> So, I assume that the value in the cells should have changed to number, but
> it hasn't. They are still formated as "general" if I check in Excel. If I
> write ffac.xl.Range("E5").Value I get up the correct value, so I must be
> working with the correct sheet.
>
> How can I change the format of the cells?

My own excel-code changes formats for a range of cells, rather than for an
entire column, but it looks like this:

        # [...]
        sh = self.xlBook.Worksheets(sheet)
        r = sh.Range(sh.Cells(row1, col1), sh.Cells(row2, col2) )
        r.NumberFormat = '$#,##0.00;[Red]-$#,##0.00'

The particular format shown is currency, with negative values displaying in
red.  (I actually retrieve the proper format string from a dictionary,
depending on the type of data I'm writing, but trimmed that to just show the
Excel-manipulating code.)

It's been a long time since I wrote this, however, so my memories of how and
why it works are a bit hazy.  :)

Jeff Shannon
Technician/Programmer
Credit International