mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-14 23:33:18 +00:00
works with hashtable
This commit is contained in:
@@ -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,10 +258,17 @@ function Export-Excel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($PivotData) {
|
if($PivotData) {
|
||||||
|
if($PivotData -is [hashtable]) {
|
||||||
|
$PivotData.Keys | % {
|
||||||
|
$df=$pivotTable.DataFields.Add($pivotTable.Fields[$_])
|
||||||
|
$df.Function = $PivotData.$_
|
||||||
|
}
|
||||||
|
} else {
|
||||||
foreach ($Item in $PivotData) {
|
foreach ($Item in $PivotData) {
|
||||||
$null=$pivotTable.DataFields.Add($pivotTable.Fields[$Item])
|
$null=$pivotTable.DataFields.Add($pivotTable.Fields[$Item])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if($IncludePivotChart) {
|
if($IncludePivotChart) {
|
||||||
$chart = $wsPivot.Drawings.AddChart("PivotChart", $ChartType, $pivotTable)
|
$chart = $wsPivot.Drawings.AddChart("PivotChart", $ChartType, $pivotTable)
|
||||||
|
|||||||
Reference in New Issue
Block a user