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.#!usr/bin/perl -wl use Font::TTFMetrics; my $font = Font::TTFMetrics->new('c:\windows\fonts\arial.ttf'); my $font_size = 10; my $dpi = 96; my $units_per_em = $font->get_units_per_em(); my $font_width = $font->string_width("Some sort of long string") +; # The following expression is from the TTFMetrics docs. my $pixel_width = $font_width *$font_size *$dpi /(72 *$units_per_ +em); # The following expression is from the Spreadsheet::WriteExcel int +ernals. my $cell_width = ($pixel_width -5) /7; # For cell widths > 1 print $cell_width;
--
John.
In reply to Re: Excel Width Calculation
by jmcnamara
in thread Excel Width Calculation
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |