我一直在使用此Github Link生成数据透视表。我有一个预先填充的excel文件[File.xslx],并希望从该数据生成数据透视表。以下是我使用的代码段。
Export-Excel -Path "Path/to/excel/file.xslx" -IncludePivotTable -PivotRows "Row Name" -PivotData "Data Column"
然而,这会引发以下错误:
You cannot call a method on a null-valued expression.
$isDataTypeValueType = $TargetData.GetType().name -match
注意:所有必需的模块都已导入PS脚本
更新-1
我能够重复这个问题,现在代码看起来像
$Imported = Import-XLSX -Path path\to\excel\file.xlsx -Header "Column-1","Column-2","Column-3","Column-4","Column-5","Column-6","Column-7","Column-8"
$Imported| Export-Excel -Path "Path/to/excel/file.xslx" -IncludePivotTable -PivotRows "column-1" -PivotData @{"column-6"="sum";"column-7"="Sum"} -PivotColumns "column-2" -Show
它能够生成数据透视表,但问题是自动生成的Summantion列名为“Values”被添加到Rows部分,而我希望它被添加到columns部分。你能告诉我如何去做吗?
更新-2
我现在能够解决值字段问题我想将它移动到列部分列表的顶部
我的代码现在看起来像这样:
$Imported| Export-Excel -Path path\to\excel\file.xlsx -IncludePivotTable -PivotColumns "column-1" -PivotDataToColumn -PivotData @{"Column-2"="Sum";"column-3"="Sum"} -PivotRows "column-4" -AutoSize -BoldTopRow -Show
目前,价值字段最终显示为低优先级。请告诉我如何将其移动?