Possible to have data and charts on separate worksheets? #1319
Answered
by
dfinke
Catalyst8487
asked this question in
Q&A
-
|
I'm working with one of the examples, MultipleCharts.ps1... This creates a single worksheet w/ both the data and the charts. I'd like to separate these out with the data on one sheet and charts on a separate - My real dataset is much larger with about two dozen columns and hundreds of rows... Dropping charts onto the same worksheet would not be ideal since they would be way far to the right, way down at the bottom, or on top of the data. |
Beta Was this translation helpful? Give feedback.
Answered by
dfinke
Nov 21, 2022
Replies: 1 comment 2 replies
-
Try this:$xlSourcefile = "$PSScriptRoot\spike.xlsx"
Remove-Item $xlSourcefile -ErrorAction Ignore
$data = ConvertFrom-Csv @"
ID,Product,Quantity,Price,Total
12001,Nails,37,3.99,147.63
12002,Hammer,5,12.10,60.5
12003,Saw,12,15.37,184.44
12010,Drill,20,8,160
12011,Crowbar,7,23.48,164.36
"@
$excel = $data | Export-Excel -Path $xlSourcefile -AutoFilter -AutoNameRange -AutoSize -PassThru
$null = Add-Worksheet -ExcelPackage $excel -WorksheetName "Charts" -Activate
Add-ExcelChart -Worksheet $excel.Charts -YRange "Sheet1!Price" -XRange "Sheet1!Product" -Title "Item price" -NoLegend -Height 225
Add-ExcelChart -Worksheet $excel.Charts -YRange "Sheet1!Total" -XRange "Sheet1!Product" -Title "Total sales" -NoLegend -Height 225 -Row 9 -Column 15
Add-ExcelChart -Worksheet $excel.Charts -YRange "Sheet1!Quantity" -XRange "Sheet1!Product" -Title "Sales volume" -NoLegend -Height 225 -Row 15
Close-ExcelPackage $excel -Show |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
Catalyst8487
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try this: