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

Hello All, I am currently attempting to create an Excel workbook that contains several sheets of data, and on some sheets, charts.

The problem that I'm running into is that the $Chart->Location function does not place the chart on the worksheet I specify; it keeps putting it on the very first sheet.

Below is a snippet of the code where I write data to a sheet and then attempt to create a chart from that data. Both charts end up being placed on the very first sheet.

#------------------------------------------------------------ # Make the all_amr_by_builds Sheet #____________________________________________________________ $Sheet = $Book->Worksheets($allamrbybuildsNum); $Sheet2 = $Book->Worksheets($allbuildsdataNum); $row = 2; $col = 1; $val = "SMRs Authorized to AMR Builds:"; &Write($row, $col, $val, 3); $row = $row + 1; foreach $oldRow (2..$rows[0]) { $col = 1; foreach $oldCol (1..7) { $val = $Sheet2->Cells($oldRow, $oldCol)->{'Value'}; if ((!($val)) && ($oldRow != 2)) { $val = "=0"; } if ($oldRow != 2) { &Write($row, $col, $val, 1); } else { &Write($row, $col, $val, 4); } $col = $col + 1; } $row = $row + 1; } #------------------------------------------------------------ # Make the all_amr_by_builds Chart #____________________________________________________________ $sourceRow = $row-1; $Range = $Sheet->Range("A3:G$sourceRow"); $Chart = $Book->Charts->Add; #$Chart->{ChartType}=xlBarClustered; $Chart->{ChartType}=xlColumnClustered; $Chart->SetSourceData({Source => $Range, PlotBy => xwColumns}); $Chart->{HasTitle} = 1; $Chart->ChartTitle->{Text} = "SMRs Assigned by Build"; $Chart->ChartTitle->Font->{Size}=10; $Chart->{HasLegend} = 1; $Chart->Legend->{Position} = xlBottom; $Chart->Axes(xlCategory, xlPrimary)->{HasTitle} = 1; $Chart->Axes(xlCategory, xlPrimary)->AxisTitle->{Text} = "By Build/Sev +erity Rating"; $Chart->Axes(xlCategory, xlPrimary)->AxisTitle->Font->{Size}=10; $Chart->Axes(xlValue, xlPrimary)->{HasTitle} = 1; $Chart->Axes(xlValue, xlPrimary)->AxisTitle->{Text} = "# of SMRs"; $Chart->Axes(xlValue, xlPrimary)->AxisTitle->Font->{Size}=10; $Chart->Location({Where => xlLocationAsObject, Name => $Sheet->{Name}} +); #$Chart = $Excel->ActiveChart; #------------------------------------------------------------ # Make the history_cati-1s Sheet #____________________________________________________________ $Sheet = $Book->Worksheets($histcati1sNum); $Sheet2 = $Book->Worksheets($histdataNum); $row = 1; $col = 1; $val = "Cumulative Status of CATI-1 SMRs (Less BCRs) - Authorized vs. +Resolved vs. Closed"; &Write($row, $col, $val, 3); $row = $row + 1; @histCATIheaders = ('Workflow States', 'Authorized to Work - Cumulativ +e', 'Resolved', 'Closed-Cumulative'); foreach $val (@histCATIheaders) { &Write($row, $col, $val, 4); $col = $col + 1; } $row = $row + 1; foreach $oldCol (2..$cols[4]) { $col = 1; foreach $oldRow (1..4) { $val = $Sheet2->Cells($oldRow, $oldCol)->{'Value'}; &Write($row, $col, $val, 1); $col = $col + 1; } $row = $row + 1; } #------------------------------------------------------------ # Make the history_cati-1s Chart #____________________________________________________________ $name = "history_cati-1s"; my $Sheet = $Book->Worksheets("history_cati-1s"); $Sheet->Activate(); $sourceRow = $row-1; $Range = $Sheet->Range("A3:D$sourceRow"); $Chart = $Book->Charts->Add; $Chart->{ChartType}=xlColumnClustered; $Chart->SetSourceData({Source => $Range, PlotBy => xwColumns}); $Chart->{HasTitle} = 1; $Chart->ChartTitle->{Text} = "AMR"; $Chart->ChartTitle->Font->{Size}=10; $Chart->{HasLegend} = 1; $Chart->Axes(xlCategory, xlPrimary)->{HasTitle} = 1; $Chart->Axes(xlCategory, xlPrimary)->AxisTitle->{Text} = "By Week"; $Chart->Axes(xlCategory, xlPrimary)->AxisTitle->Font->{Size}=10; $Chart->Axes(xlValue, xlPrimary)->{HasTitle} = 1; $Chart->Axes(xlValue, xlPrimary)->AxisTitle->{Text} = "# of SMRs"; $Chart->Axes(xlValue, xlPrimary)->AxisTitle->Font->{Size}=10; $Chart->Location({Where => xlLocationAsObject, Name => $Sheet->{Name}} +); #$Chart->Location(xlLocationAsObject, $name); #$Chart->Location(xlLocationAsObject, $Sheet->{Name}); #$Chart->Location(xlLocationAsObject, "history_cati-1s"); #$Chart->Location(2, $sheetName); $Chart = $Excel->ActiveChart;
Any help is appreciated,
Thanks ~Vanessa L.~

BazB added readmore tags

Replies are listed 'Best First'.
Re: Creating Multiple Excel Graphs on different Sheets
by JamesNC (Chaplain) on Feb 19, 2004 at 04:55 UTC
    Looks like you tried most everything, except explicity naming the sheet, try
    $Chart->Location('xlLocationAsObject', "Sheet1");

    Hope it works, I don't see the rest of your stuff. I tried this on VB and it moved the chart.

    JamesNC
      James,
      I attempted giving the name of the sheet like you showed, but it still does not work. If I gave you the whole script, do you think it might help?

      Thanks,
      ~Vanessa~
        Email it to me: jmoosmann@earthlink.com
        I honestly can't look at it until I get off of work though.

        JamesNC
Re: Creating Multiple Excel Graphs on different Sheets
by CountZero (Bishop) on Feb 18, 2004 at 22:30 UTC
    Isn't there a way to move the sheets with the graphs to their right place? I think it is standard behaviour of Excel to place a new chart-sheet in the first place.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law