Add a trendline to an existing excel chart using PowerShell
i have script opens csv , imports data excel using comobject:
$opslist = import-csv -delimiter ',' c:\powershell\example.csv -header @("number","name","stat") $count = 1 $xl = new-object -comobject "excel.application" $wb=$xl.workbooks.add() $ws=$wb.activesheet $xl.visible=$true $cells=$ws.cells foreach ($op in $opslist) { $cells.item($count,1) = $op.number $cells.item($count,2) = $op.name $cells.item($count,3) = $op.stat $count = $count + 1 } $chart = $xl.charts.add() $chart.charttype = 65
i'd add trendline chart. recorded excel macro, 1 bit beyond me. macro follows, if tell me powershell code use, i'd appreciate it
activechart.chartarea.select activechart.seriescollection(1).select activechart.seriescollection(1).trendlines.add activechart.seriescollection(1).trendlines(1).select selection.type = xllogarithmic selection.format.line .visible = msotrue .forecolor.objectthemecolor = msothemecoloraccent1 .forecolor.tintandshade = 0 .forecolor.brightness = 0 end selection.format.line .visible = msotrue .forecolor.rgb = rgb(255, 0, 0) .transparency = 0 end selection.format.line .visible = msotrue .weight = 2 end with
thank you
zarberg@gmail.com
as happens, found answer playing around
$chart.seriescollection(1).trendlines().add(-4133)
zarberg@gmail.com
Windows Server > Windows PowerShell
Comments
Post a Comment