Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Excel Width Calculation
by bmann (Priest) on Aug 19, 2004 at 19:44 UTC | |
Win32::API and a search on MSDN for GetTextExtentPoint32 should get you started. Hope this helps you get started... | [reply] |
|
Re: Excel Width Calculation
by jmcnamara (Monsignor) on Aug 20, 2004 at 00:08 UTC | |
Here is one way using Font::TTFMetrics: I did a quick check with a few string lengths and point sizes and I got approximately the right answers. However, you may want to increase the final width by a small percentage to allow for a border. There are also some other font metric modules on CPAN that you might prefer.
--
| [reply] [d/l] |
by Anonymous Monk on Aug 20, 2004 at 21:38 UTC | |
| [reply] [d/l] |
|
Re: Excel Width Calculation
by Grygonos (Chaplain) on Aug 19, 2004 at 20:19 UTC | |
Excel calculates its cell width in points (1/72 of an inch). Given the width of each character in a font face for a given font size. Take your lengthiest string (which may not neccessarily need the most room (but should on most occassions) and then calculate how many points are needed to hold that string by The length of the string has nothing to do with the calculation unless you are using a fixed width font face. In which case you can multiply the number of letters in the string by the width of a character in that font face for that font size
Also, just a question..When you say auto-sized cells, I assume you mean at point of initial template creation. To my knowledge there is no means to keep a cell auto-sized as the data in it changes. | [reply] [d/l] [select] |
|
Re: Excel Width Calculation
by dragonchild (Archbishop) on Aug 19, 2004 at 19:51 UTC | |
As for calculating ... Excel does funky stuff when it comes display stuff. jmcnamara might know more. ------
Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose I shouldn't have to say this, but any code, unless otherwise stated, is untested | [reply] |