>
> Note that, for some reason, I don't have the file
> zoom_magnification.py in the examples folder.
How did you install xlwt, and where did you install xlwt?
I think John Machin probably hates that I've done this, and hates more
that I mention it when people ask, but I've gathered approximate
widths for common characters in Arial 10 (most people's default Excel
font) and provided it in the arial10.py file in the files section of
this group, so you can build your own autofit routines. (I included a
very rudimentary one in arial10.py.) The process is quite ugly and
slow: You have to calculate the width of each cell as you're writing
it, keeping track of the maximum width and using that to set the
column width after you have finished writing all the cells in that
column.
Depending on the data being fitted and the formatting you're using, it
can be much trickier and more error-prone than it sounds. If your
needs are complex (using formulas, for example) then it becomes
impossible or close to it. At some point, it's simpler, easier, and
faster to just use Excel itself to do this task (it can be controlled
programmatically by various means, including Python using COM).
John Y.
You think incorrectly. It's a brave, noble, heroic effort. But
misdirected IMHO. "C'est magnifique, mais ce n'est pas la guerre."
> and hates more
> that I mention it when people ask,
Not at all. I do regret that people don't search for previous discussion.
> but I've gathered approximate
> widths for common characters in Arial 10 (most people's default Excel
> font) and provided it in the arial10.py file in the files section of
> this group, so you can build your own autofit routines. (I included a
> very rudimentary one in arial10.py.) The process is quite ugly and
> slow: You have to calculate the width of each cell as you're writing
> it, keeping track of the maximum width and using that to set the
> column width after you have finished writing all the cells in that
> column.
>
> Depending on the data being fitted and the formatting you're using, it
> can be much trickier and more error-prone than it sounds. If your
> needs are complex (using formulas, for example) then it becomes
> impossible or close to it. At some point, it's simpler, easier, and
> faster to just use Excel itself to do this task (it can be controlled
> programmatically by various means, including Python using COM).
Or Python using pyuno to drive OpenOffice ...
Cheers,
John