Hello, I am using Active Perl 5.8.0 Build 819 and have created a program which will parse data out of a MS Access DB. I am then taking the data parsed and output it formated in Excel using the Win32::OLE. The problem I am having is when I try to generate an XYLine Graph. I got some sample code and was trying it but seems like I get an error when I try to Name the chart title, enable the legend, or name the Data Series.
The error is the following when trying to name the chart title:
OLE exception from "Microsoft Office Excel": Unable to set the HasTitle property of the Chart class Win32::OLE(0.1707) error 0x80020009: "Exception occurred" in PROPERTYPUT "HasTitle" at Processor.pl line 1044

Line 1044 is the following in the code below:
$mcr_crtime_chart->{HasTitle} = 1; $mcr_crtime_chart->ChartTitle->{Text} = "MCRByURN-CreateTime";

The error is the following when trying to enable the legend:
OLE exception from "Microsoft Office Excel": Unable to set the Position property of the Legend class Win32::OLE(0.1707) error 0x80020009: "Exception occurred" in PROPERTYPUT "Position" at Processor.pl line 1043

Line 1043 is the following from the code below:
$mcr_crtime_chart->{HasLegend} = 1; $mcr_crtime_chart->Legend->{Position} = xlRight;

The error is the following when trying to name a series:

OLE exception from "Microsoft Office Excel": Unable to set the Name property of the Series class Win32::OLE(0.1707) error 0x80020009: "Exception occurred" in PROPERTYPUT "Name" at Processor.pl line 1056


Line 1056 is the following line of code $mcr_crtime_chart->SeriesCollection($p)->{Name} = "Series $p"; in the code below (Last Line in the for loop)
The Code I am using is trying to graph N number of series worth of data and therefore has the FOR LOOP. The code is as follows:
use OLE; use Win32::OLE qw(in with); use Win32::OLE::Const "Microsoft Excel"; use Win32::OLE::Variant; use Win32::OLE::NLS qw(:LOCALE :DATE); $Excel = Win32::OLE->GetActiveObject('Excel.Application')||Win32::OLE- +>new('Excel.Application','Quit'); $Excel->{DisplayAlerts}=0; $Excel->{SheetsInNewWorkbook} = 16; $Book = $Excel->Workbooks->Add; $mcr_crtime_chart = $Excel->Charts->Add({After => $mcrsa_crtab_she +et}); $mcr_crtime_chart->{Name} = "CreateTime_Graph"; $mcr_crtime_chart->{ChartType} = xlXYScatterLines; $mcr_crtime_chart->{HasLegend} = 1; # $mcr_crtime_chart->Legend->{Position} = xlRight; # $mcr_crtime_chart->{HasTitle} = 1; # $mcr_crtime_chart->ChartTitle->{Text} = "MCRByURN-CreateTime"; $x_range = $mcrsa_crtab_sheet->Range("B2:B69"); $mcr_crtime_chart->SetSourceData($mcrsa_crtab_sheet->Range("A2:D69 +"),xlColumns); $mcr_crtime_chart->SeriesCollection->LetProperty('XValues',$x_rang +e); for ($p = 2; $p < $ct_max_column; $p++) { $y_range[$p] = $mcrsa_crtab_sheet->Range("$LetterByNumber{$p}2:$ +LetterByNumber{$p}$ct_row"); $mcr_crtime_chart->SeriesCollection($p)->LetProperty('YValues',$ +y_range[$p]); $mcr_crtime_chart->SeriesCollection($p)->{Name} = "Series $p"; } my $Xaxes = $mcr_crtime_chart->Axes(xlCategory,xlPrimary); $Xaxes->{HasTitle} = 1; $Xaxes->{AxisTitle}->{Characters}->{Text} = "Create Time (sec)"; my $Yaxes = $mcr_crtime_chart->Axes(xlValue,xlPrimary); $Yaxes->{HasTitle} = 1; $Yaxes->{AxisTitle}->{Characters}->{Text} = "MCR (%)";
If anyone has any suggestions they would be greatly appreciated. Thanks in advance!

In reply to Problem Graphing to Excel with Win32::OLE by ralife

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.