On Nov 3, 7:03 am, "rpno
...@ibksoftware.com" <rpno
...@ibksoftware.com>
wrote:
> I have several png files that represent trends (up, down and no
> change). They are 16px x 16px, Can they be centered using formats?
> Currently they are flush left. Do I need to create the graphic as wide
> as the column? Thge column width is 10 row height is 22.
Hi Rob,
Images (and other objects) are layered on top of a worksheet so they
aren't in general controlled by formatting.
In the case of images you will need to specify your own offsets to
centre the image using the optional $x, $y parameters in insert_image
().
http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel/lib/Spreadsh...)
The default cell width is 64 pixels and the default height is 17
pixels. So to centre a 16x16 image you will need the following
offsets:
x = int( ( 64 - 16) / 2 ) = 24
y = int ( ( 17 - 16) /2 ) = 0
Here is an example:
#!/usr/bin/perl
use strict;
use warnings;
use Spreadsheet::WriteExcel;
my $workbook = Spreadsheet::WriteExcel->new('test.xls');
my $worksheet = $workbook->add_worksheet();
# Left top align.
$worksheet->insert_image('B3', '16x16.png');
# Centred. x = int( ( 64 - 16) / 2 ), y = int ( ( 17 - 16) /2 ).
$worksheet->insert_image('B5', '16x16.png', 24, 0);
# Right bottom align. x = ( 64 - 16), y = ( 17 - 16).
$worksheet->insert_image('B7', '16x16.png', 48, 1);
__END__
John.
--