merrymonk has asked for the wisdom of the Perl Monks concerning the following question:
use OLE; use Win32::OLE::Const "Microsoft Excel"; use strict "vars"; my ($excel, $workbook, $sheet); my ($w1, $w2, $w3, $w4); #___ DEFINE EXCEL $excel = CreateObject OLE "Excel.Application"; #___ MAKE EXCEL VISIBLE $excel -> {Visible} = 1; #___ ADD NEW WORKBOOK $workbook = $excel -> Workbooks -> Add; $sheet = $workbook -> Worksheets("Sheet1"); $sheet -> Activate; # find initial width of B4 $w1 = $sheet->Range("B4")->Width; # add text to B4 and autofit the cell $sheet -> Range("B4") -> {Value} = "The cat sat on the mat"; $sheet -> Range("B4") -> Columns -> {AutoFit} = "True"; # find new width of B4 $w2 = $sheet->Range("B4")->Width; # 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; # set column F to 60 $sheet -> Range("F4") -> {ColumnWidth} = 60; # find width of column F $w4 = $sheet->Range("F4")->Width; print "F4 width 1<$w1> 2 <$w2> H4 width <$w3> F4 width <$w4>\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Problems setting Excel cell width
by hominid (Priest) on Jan 27, 2010 at 15:14 UTC | |
by merrymonk (Hermit) on Jan 27, 2010 at 16:33 UTC | |
by hominid (Priest) on Jan 27, 2010 at 20:25 UTC |