Nalina has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

I am using excel chart wizard to generate chart & then exporting the chart to a png file. The code is
use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; use Win32::OLE::Variant; use Win32::OLE::NLS qw(:LOCALE :DATE); use Win32::OLE; use Win32::OLE::Const; $Win32::OLE::Warn = 3; # die on errors... $file = shift; $Date = shift; chomp($Date); $row=1; open (DATA, $file) || die "can't open $file"; @line = <DATA>; @array = split(/\|/, $line[0]); $Max = -1; foreach $temp (@line) { @array = split(/\|/, $temp); if (substr($array[3],0,1) =~ /^\d/) { $Max = $array[3]; $Min = $array[3]; $Sum = 0; last; } } if ($Max eq -1) { print "Valid Data not found!\n"; exit; } $n = 0; my $Constant = Win32::OLE::Const->Load('Microsoft Excel'); $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit') || die "Error launching MS Excel ".Win32::OLE->LastError; $Book = $Excel->Workbooks->Add; $Sheet = $Book->Worksheets(1); $Sheet->{Name} = "Sheet1"; $Win32::OLE::Warn = 3; # die on errors... foreach $temp (@line) { chomp($temp); $col='A'; @array = split(/\|/, $temp); if (substr($array[3],0,1) =~ /^\d/) { $Max = $array[3] if ($array[3] > $Max); $Min = $array[3] if ($array[3] < $Min); $Sum = $Sum + $array[3]; $cell = sprintf("%s%d", $col,$row); $Sheet->Range($cell)->{value} = $array[0]; $col = 'B'; $cell = sprintf("%s%d", $col,$row); $Sheet->Range($cell)->{value} = $array[3]; $row++; $n++; } } $Avg = sprintf("%0.2f",$Sum / $n); $Excel->{Visible} = 1; my $Range = $Sheet->Range("B1:B$row"); my $Chart = $Sheet->ChartObjects; my $AgeChartContainer = $Chart->Add(200,30,500,300); my $AgeChart = $AgeChartContainer->Chart; $AgeChart->{ChartType} = $Constant->{xlLineMarkers}; $AgeChart->Location($Constant->{xlLocationAsObject}, $Sh +eet->{Name}); $AgeChart = $Excel->ActiveChart; $AgeChart->{ChartType} = xlLineMarkers; $AgeChart->SetSourceData({Source => $Range, PlotBy = +> xlColumns}); $AgeChart->SeriesCollection(1)->{XValues}= "=Sheet1! +R1C1:R"."$row"."C1"; $AgeChart->{HasTitle} = 1; $AgeChart->{HasLegend} = 0; $AgeChart->ChartTitle->{Text} = "Total Memory Usage +- 192.168.218.135(MAPLE) $Date"; $AgeChart->Axes(xlCategory, xlPrimary)->{HasTitle} = + 1; $AgeChart->Axes(xlCategory, xlPrimary)->AxisTitle->{Text +} = "Time(hrs)\nMax = $Max Min = $Min Avg = $Avg "; $AgeChart->Axes(xlValue, xlPrimary)->{HasMajorGridlines} + = 1; $AgeChart->Axes(xlCategory, xlPrimary)->{HasMajorGri +dlines} = 1; $AgeChart->Axes(xlValue, xlPrimary)->MajorGridlines- +>Border->{ColorIndex} = 15; $AgeChart->Axes(xlCategory, xlPrimary)->MajorGridlin +es->Border->{ColorIndex} = 15; $AgeChart->Axes(xlValue, xlPrimary)->{HasTitle} = 1; $AgeChart->Axes(xlValue, xlPrimary)->AxisTitle->{Tex +t} = "Total Memory Used(%)"; $AgeChart->PlotArea->Border->{ColorIndex} = 16; $AgeChart->PlotArea->Interior->{ColorIndex} = 2; $Book->SaveAs('C:\\Graph2.xls'); $Book->Close({SaveChanges=>0}); my $filename="C:\\Graph2.xls"; my $filter = 'PNG'; # can be GIF, JPG, JPEG or PNG $Date = join(".",split(/\//,$Date)); my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); # use the Exc +el application if it's open, otherwise open new my $Book = $Excel->Workbooks->Open( $filename ); # open the fi +le foreach my $Sheet (in $Book->Sheets) { # loop through all shee +ts foreach my $ChartObj (in $Sheet->ChartObjects) { # loop throug +h all chartobjects in the sheet my $savename = "$filename." . "$Date" . ".$filter"; print "$savename\n"; $savename1=join("\\\\",split(/\\/,$savename)); # replace '//' + with '\' # Write image to PNG file $ChartObj->Chart->Export({ FileName => $savename, FilterName => $filter, Interactive => 0}); } } #$Sheet->delete(); #$Book->Close; $Book->Close({SaveChanges=>0}); #unlink "$filename"; # delete the xls file #$Excel->ActiveWorkbook->Close(); $Excel->Quit();
I want to copy an image from a png file & paste it to the png file into which the chart is exported from excel.

How do I copy the image from one png file to other?

Thanks & Regards Nalina

Replies are listed 'Best First'.
Re: Copy a png image
by Joost (Canon) on Aug 02, 2004 at 09:40 UTC
      Can Image::Magick module be installed using ppm? I tried 'ppm install image-magick'. But image-magick.ppd is not there in perl repository. Please give me the url to install it.

      Thanks & Regards

      Nalina