mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-11 13:53:20 +00:00
works with hashtable
This commit is contained in:
@@ -136,7 +136,8 @@ function Export-Excel {
|
||||
#[string]$TitleBackgroundColor,
|
||||
[string[]]$PivotRows,
|
||||
[string[]]$PivotColumns,
|
||||
[string[]]$PivotData,
|
||||
#[string[]]$PivotData,
|
||||
$PivotData,
|
||||
[string]$Password,
|
||||
[OfficeOpenXml.Drawing.Chart.eChartType]$ChartType="Pie",
|
||||
[Switch]$IncludePivotTable,
|
||||
@@ -203,7 +204,15 @@ function Export-Excel {
|
||||
foreach ($Name in $Header) {
|
||||
|
||||
$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) {
|
||||
{$_ -is [datetime]} {$targetCell.Style.Numberformat.Format = "m/d/yy h:mm"}
|
||||
@@ -249,10 +258,17 @@ function Export-Excel {
|
||||
}
|
||||
|
||||
if($PivotData) {
|
||||
if($PivotData -is [hashtable]) {
|
||||
$PivotData.Keys | % {
|
||||
$df=$pivotTable.DataFields.Add($pivotTable.Fields[$_])
|
||||
$df.Function = $PivotData.$_
|
||||
}
|
||||
} else {
|
||||
foreach ($Item in $PivotData) {
|
||||
$null=$pivotTable.DataFields.Add($pivotTable.Fields[$Item])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($IncludePivotChart) {
|
||||
$chart = $wsPivot.Drawings.AddChart("PivotChart", $ChartType, $pivotTable)
|
||||
|
||||
Reference in New Issue
Block a user