works with hashtable

This commit is contained in:
Doug Finke
2015-05-19 15:35:18 -04:00
committed by dfinke
parent b25193cac8
commit 20d84ace37

View File

@@ -136,7 +136,8 @@ function Export-Excel {
#[string]$TitleBackgroundColor, #[string]$TitleBackgroundColor,
[string[]]$PivotRows, [string[]]$PivotRows,
[string[]]$PivotColumns, [string[]]$PivotColumns,
[string[]]$PivotData, #[string[]]$PivotData,
$PivotData,
[string]$Password, [string]$Password,
[OfficeOpenXml.Drawing.Chart.eChartType]$ChartType="Pie", [OfficeOpenXml.Drawing.Chart.eChartType]$ChartType="Pie",
[Switch]$IncludePivotTable, [Switch]$IncludePivotTable,
@@ -203,7 +204,15 @@ function Export-Excel {
foreach ($Name in $Header) { foreach ($Name in $Header) {
$targetCell = $ws.Cells[$Row, $ColumnIndex] $targetCell = $ws.Cells[$Row, $ColumnIndex]
$targetCell.Value = $TargetData.$Name
$cellValue=$TargetData.$Name
$r=$null
if([double]::tryparse($cellValue, [ref]$r)) {
$targetCell.Value = $r
} else {
$targetCell.Value = $cellValue
}
switch ($TargetData.$Name) { switch ($TargetData.$Name) {
{$_ -is [datetime]} {$targetCell.Style.Numberformat.Format = "m/d/yy h:mm"} {$_ -is [datetime]} {$targetCell.Style.Numberformat.Format = "m/d/yy h:mm"}
@@ -249,8 +258,15 @@ function Export-Excel {
} }
if($PivotData) { if($PivotData) {
foreach ($Item in $PivotData) { if($PivotData -is [hashtable]) {
$null=$pivotTable.DataFields.Add($pivotTable.Fields[$Item]) $PivotData.Keys | % {
$df=$pivotTable.DataFields.Add($pivotTable.Fields[$_])
$df.Function = $PivotData.$_
}
} else {
foreach ($Item in $PivotData) {
$null=$pivotTable.DataFields.Add($pivotTable.Fields[$Item])
}
} }
} }