The problem is with mixed units. Width deals with pixel width (I think). ColumnWidth deals with character width (I think). So, for example, you are setting D4 width in characters to B4 width in pixels.
I modified part of your code to illustrate the difference.
...
# find initial width of B4
$w1 = $sheet->Range("B4")->Width;
my $cw1 = $sheet->Range("B4")->{ColumnWidth};
# find new width of B4
$w2 = $sheet->Range("B4")->Width;
my $cw2 = $sheet->Range("B4")->{ColumnWidth};
# set column D to cell width found for cell F4
$sheet -> Range("D4") -> {ColumnWidth} = $w2;
# find width of column D
$w3 = $sheet->Range("D4")->Width;
my $cw3 = $sheet->Range("D4")->{ColumnWidth};
# set column F to 60
$sheet -> Range("F4") -> {ColumnWidth} = 60;
# find width of column F
$w4 = $sheet->Range("F4")->Width;
my $cw4 = $sheet->Range("F4")->{ColumnWidth};
print "B4 width 1<$w1> 2 <$w2> D4 width <$w3> F4 width <$w4>\n";
print "B4 colwidth 1<$cw1> 2 <$cw2> D4 colwidth <$cw3> F4 colwidth <$c
+w4>\n";
Which gives the result:
B4 width 1<48> 2 <105> D4 width <555> F4 width <318.75>
B4 colwidth 1<8.43> 2 <19.29> D4 colwidth <105> F4 colwidth <60>
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.