-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathExample-ExcelChartFormatting.ps1
More file actions
29 lines (25 loc) · 1.2 KB
/
Example-ExcelChartFormatting.ps1
File metadata and controls
29 lines (25 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$modulePath = if ($env:PSWRITEOFFICE_MODULE_MANIFEST) {
$env:PSWRITEOFFICE_MODULE_MANIFEST
} else {
(Join-Path $PSScriptRoot '..\..\PSWriteOffice.psd1')
}
if (-not (Get-Module -Name PSWriteOffice)) { Import-Module $modulePath -ErrorAction Stop }
$documents = Join-Path $PSScriptRoot '..\Documents'
New-Item -Path $documents -ItemType Directory -Force | Out-Null
$path = Join-Path $documents 'Excel-ChartFormatting.xlsx'
$rows = @(
[PSCustomObject]@{ Region = 'NA'; Revenue = 100 }
[PSCustomObject]@{ Region = 'EMEA'; Revenue = 200 }
[PSCustomObject]@{ Region = 'APAC'; Revenue = 150 }
)
New-OfficeExcel -Path $path {
Add-OfficeExcelSheet -Name 'Data' -Content {
Add-OfficeExcelTable -Data $rows -TableName 'Sales' -AutoFit
$chart = Add-OfficeExcelChart -TableName 'Sales' -Row 6 -Column 1 -Type Pie -Title 'Revenue Mix' -PassThru
$chart |
Set-OfficeExcelChartLegend -Position Right |
Set-OfficeExcelChartDataLabels -ShowValue $true -ShowPercent $true -Position OutsideEnd -NumberFormat '0.0%' -SourceLinked:$false |
Set-OfficeExcelChartStyle -StyleId 251 -ColorStyleId 10 | Out-Null
}
} | Out-Null
Write-Host "Workbook saved to $path"