使用PowerShell在一个Excel工作簿中创建多个数据透视表

时间:2018-09-12 09:37:03

标签: excel powershell

这里确实需要正确的方向,我试图在1个Excel工作簿中的5个单独的工作表中创建5个单独的数据透视表。

第一个数据透视表创建完美,但是其余4个却没有,在Powershell ISE中运行脚本时收到以下4个警告。

  

警告:添加数据透视表“成本分析”失败:索引操作   失败数组索引计算为null。

     

警告:无法添加数据透视表'Cost Over Time':索引操作   失败数组索引计算为null。

     

警告:添加数据透视表“随着时间的实际费用”失败:索引   手术失败;数组索引计算为null。

     

警告:无法添加数据透视表“实例成本分配”:索引   手术失败;数组索引计算为null。

使用的代码如下。

Import-Excel 'C:\scripts\MSCR.xlsx' | Export-Excel -Path 'C:\scripts\MSCRout.xlsx' -WorkSheetname 'Actual Cost Analysis' -Show -PivotTableDefinition @{

"Actual Cost Analysis" = @{"SourceWorkSheet" = "Actual Cost Analysis";
         "PivotRows"         = "Service";
         "PivotData"         = @{"Total Cost"=”Sum”};
         "IncludePivotChart" = $true;
         "ChartType"         = "ColumnClustered";
         "NoLegend"          = $true};
"Actual Cost Over Time" = @{"SourceWorkSheet" = "Actual Cost Over Time"; 
         "PivotRows"         = "Date"; 
         "PivotData"         = @{"Total Cost"="Sum"}; 
         "IncludePivotChart" = $true; 
         "ChartType"         = "ColumnClustered"; 
         "NoLegend"          = $true };

"Cost Analysis" = @{"SourceWorkSheet" = "Cost Analysis"; 
         "PivotRows"         = "ID"; 
         "PivotData"         = @{"Total Cost"="Sum"}; 
         "IncludePivotChart" = $true            ; 
         "ChartType"         = "ColumnClustered"; 
         "NoLegend"          = $true };

"Cost Over Time" = @{"SourceWorkSheet" = "Cost Over Time"; 
         "PivotRows"         = "Date"; 
         "PivotData"         = @{"Total Cost"="Sum"}; 
         "IncludePivotChart" = $true ; 
         "ChartType"         = "ColumnClustered"; 
         "NoLegend"          = $true}

"Instance Cost Allocation" = @{"SourceWorkSheet" = "Instance Cost 
 Allocation"; 
         "PivotRows"         = "Service"; 
         "PivotData"         = @{"Cost"="Sum"}; 
         "IncludePivotChart" = $true ; 
         "ChartType"         = "ColumnClustered"; 
         "NoLegend"          = $true}                 
}

非常感谢。

0 个答案:

没有答案