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

In reply to Copy a png image by Nalina

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.