Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Office objects

Status
Not open for further replies.

alanwes

Programmer
Aug 5, 2008
5
GB
Hi,

I have managed to add a piechart to a word document using the following code, but I cant manage to get the pie chart to have percentage values, this is available using the .HasPercentage = True value but I cant get it right, can anyone help ?

Thanks

$msWord = New-Object -Com Word.Application
# Create new document
$wordDoc = $msWord.Documents.Add()
# Make word visible (optional)
$msWord.Visible = $true
# Activate the new document
$wordDoc.Activate()

$Caption = "Simple Example"

$categories = @()
$values = @()
$chart = new-object -com OWC11.ChartSpace.11
$chart.Clear()
$c = $chart.charts.Add(0)
$c.Type = 18
$c.HasTitle = "True"
$c.HasLegend = "True"
$series = ([array] $chart.charts)[0].SeriesCollection.Add(0)

Get-Process | foreach-object {
$categories += $_.Name
$values += $_.CPU * 1
}

$series.Caption = $Caption
$series.SetData(1, -1, $categories)
$series.SetData(2, -1, $values)
$filename = (resolve-path .).Path + "\PIE.jpg"
$chart.ExportPicture($filename, "jpg", 800, 500)

$objSelection = $msWord.Selection
$msword.Selection.EndKey(6)
$objSelection.TypeParagraph()
$msWord.Application.Selection.InlineShapes.AddPicture($filename) > Null
 
Sorry,

needed to add the following lines which i worked out by looking at vb versions of the same thing and also using the get-member cmdlet.

$dl = $series.DataLabelsCollection.Add()
$dl.HasPercentage = "True
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top