mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Add Excel builtin DSUM Example
This commit is contained in:
BIN
Examples/Excel - DSUM/DSUM.png
Normal file
BIN
Examples/Excel - DSUM/DSUM.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 58 KiB |
31
Examples/Excel - DSUM/ExcelDSUMBuiltIn.ps1
Normal file
31
Examples/Excel - DSUM/ExcelDSUMBuiltIn.ps1
Normal file
@@ -0,0 +1,31 @@
|
||||
# DSUM
|
||||
# Adds the numbers in a field (column) of records in a list or database that match conditions that you specify.
|
||||
|
||||
$xlfile = "$env:TEMP\test.xlsx"
|
||||
Remove-Item $xlfile -ErrorAction SilentlyContinue
|
||||
|
||||
$data = ConvertFrom-Csv @"
|
||||
Color,Date,Sales
|
||||
Red,1/15/2018,250
|
||||
Blue,1/15/2018,200
|
||||
Red,1/16/2018,175
|
||||
Blue,1/16/2018,325
|
||||
Red,1/17/2018,150
|
||||
Blue,1/17/2018,300
|
||||
"@
|
||||
|
||||
$xl = Export-Excel -InputObject $data -Path $xlfile -AutoSize -AutoFilter -TableName SalesInfo -AutoNameRange -PassThru
|
||||
|
||||
$databaseAddress = $xl.Sheet1.Dimension.Address
|
||||
Set-Format -Worksheet $xl.Sheet1 -Range C:C -NumberFormat '$##0'
|
||||
|
||||
Set-Format -Worksheet $xl.Sheet1 -Range E1 -Value Color
|
||||
Set-Format -Worksheet $xl.Sheet1 -Range F1 -Value Date
|
||||
Set-Format -Worksheet $xl.Sheet1 -Range G1 -Value Sales
|
||||
|
||||
Set-Format -Worksheet $xl.Sheet1 -Range E2 -Value Red
|
||||
|
||||
Set-Format -Worksheet $xl.Sheet1 -Range E4 -Value Sales
|
||||
Set-Format -Worksheet $xl.Sheet1 -Range F4 -Formula ('=DSUM({0},"Sales",E1:G2)' -f $databaseAddress) -NumberFormat '$##0'
|
||||
|
||||
Close-ExcelPackage $xl -Show
|
||||
Reference in New Issue
Block a user