我创建了一个希望输出到 CSV 文件的动态对象。到目前为止,我只完成了在一列、一个单元格中具有值或输出对象描述(例如字符串长度)的不同变体。
我的 HashTable 对象是按照以下方式创建的:
$item = @{"Total"=0; "Complete"= 0}
$obj=@{"AllCounted" = 0 }
# gets outside data
foreach($field in $data){
$obj+=@{$field = $item}
$obj[$field]+= @{ $subField = $item }
这导致以下对象
$obj{
"AllCounted" = [int]
"dynamicField1"= {
"Total" =[int];
"Complete" =[int]
"SubField1" ={
"Total" =[int];
"Complete" =[int]
}
}
"dynamicField _ N"= {
"Total" =[int];
"Complete" =[int]
"SubField _ N" ={
"Total" =[int];
"Complete" =[int]
}
}
}
我的目标是
$obj.Keys|%{
$_ +","+$obj[$_]["Total"]+","+ $obj[$_]["Complete"] | Out-File "something.csv" -append"
foreach($innerLoop in $obj[$_].Keys){
","+ $_ +","+$obj[$_]["Total"]+","+ $obj[$_]["Complete"] | Out-File "something.csv" -append"
}
}
CSV 显示
Field1 | Total | Complete
| SubField1 | Total | Complete
| SubField2 | Total | Complete
| SubField N | Total | Complete
Field2 | Total | Complete
| SubField1 | Total | Complete
| SubField2 | Total | Complete
| SubField N | Total | Complete
Field N | Total | Complete
| SubField1 | Total | Complete
| SubField2 | Total | Complete
| SubField N | Total | Complete
所有的想法,但仍在尝试..