View Single Post
Old 10-12-2008   #1 (permalink)
M. Capel


Vista Ultimate x64
 
 

Problems creating trendlines in powershell-created excel chart

I'm trying to generate some simple linear regression charts in excel, driven by a powershell script. The only problem so far is that I a get an invocation failure in powershell when I attempt to generate Trendlines from the two SeriesCollections in the chart. I'm using powershell 1.0 (x64) and excel 2003. Any idea what's wrong the the script (below)?

ChDir "c:\conheap"
$xl = new-object -comobject excel.application
$xl.Visible = $true
$file = "c:\conheap\bcc_final.dat"
$xl.workbooks.OpenText($file,437,1,1,1,$True,$True,$False,$False,$True,$False)
$wkb = $xl.workbooks.item(1)
$wks = $wkb.worksheets.item(1)
$wks.select()
$xlyscatter = -4169
$rng = $wks.range("A1:C21")
$rng.select()
$ac = $wkb.Charts.Add()
$ac.ChartType = -4169
$ac.setSourceData($rng)
$ac.seriesCollection(1).xValues=$wks.range("A1:A21")
$ac.seriesCollection(2).xValues=$wks.range("A1:A21")

$ac.SeriesCollection(1).select()
$ac.SeriesCollection(1).Trendlines.Add(-4132,0,0,0,$True,$True)

$ac.SeriesCollection(2).select()
$ac.SeriesCollection(2).Trendlines.add(-4132,0,0,0,$True,$True)


Output from powershell:
True
True
Method invocation failed because [System.Management.Automation.PSMethod]
doesn't contain a method named 'Add'.
At C:\conheap\bcc_excel.ps1:34 char:39
+ $ac.SeriesCollection(1).Trendlines.Add( <<<< -4132,0,0,0,$True,$True)
True
Method invocation failed because [System.Management.Automation.PSMethod]
doesn't contain a method named 'Add'.

At C:\conheap\bcc_excel.ps1:39 char:39
+ $ac.SeriesCollection(2).Trendlines.add( <<<< -4132,0,0,0,$True,$True)
My System SpecsSystem Spec