Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Problems setting Excel cell width

by hominid (Priest)
on Jan 27, 2010 at 15:14 UTC ( [id://819945]=note: print w/replies, xml ) Need Help??


in reply to Problems setting Excel cell width

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>

Replies are listed 'Best First'.
Re^2: Problems setting Excel cell width
by merrymonk (Hermit) on Jan 27, 2010 at 16:33 UTC
    Thanks for that. I wondered if it was a units issue .
    Do you happen to know if there is some way of retrieving and setting a cell or column width that uses the same unit?
      ColumnWidth will do it.

      To set:

      $sheet -> Range("F4") -> {ColumnWidth} = 60;
      To get:
      my $columnwidth = $sheet -> Range("F4") -> {ColumnWidth};

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://819945]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-03-28 20:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found