标题和字段数量会随着我使用的不同CVS而改变,所以我不能用硬编码。
目前我使用以下代码填充清单框中的标题,但它会在一行中生成所有内容
Get-Content $list | select -First 1
显示如下
名称,种类,年龄,品种,投篮
我想要它做的是在像这样的复选框旁边生成名称
名称 种类 年龄 品种 镜头
然后我可以继续将检查字段导出为CSV。提前谢谢
出来的是程序正是我要找的谢谢。但我现在的问题是尝试将其集成到程序中我希望它是一个单行修复程序,整个问题非常大,但这是我遇到问题的部分。这是原始代码
此部分将加载CSV
$MasterBtn_Click={
if($openfile.ShowDialog() -eq 'OK')
{
$MasterTxT.Text = $openfile.FileName
$MasterLT = $MasterTxT.Text
}
$labelFormHeaders.Text = Get-Content $MasterLT | select -First 1
}
此部分比较并导出我的选择
$buttonStartProcess_Click={
$script:CancelLoop = $false
$buttonCancelProcess.Enabled = $true
$this.Enabled = $false
$progressbar1.Value = 0
for($i = 0; $i -lt $progressbar1.Maximum; $i++)
{
#----------------------------------------
$col1 = $textbox1.text
$col2 = $textbox2.text
$col3 = $textbox3.text
$col4 = $textbox4.text
$col5 = $textbox5.text
$col6 = $textbox6.text
$list = $EventLt
$Data = $MasterLT
$Userlist = Import-csv -path $list
$userData = Import-Csv -Path $Data
$UserOutput = @()
$Result = "C:\Temp\Results1.csv"
ForEach ($name in $UserList)
{
$userMatch = $UserData | where {$_.ID -eq $name.usernames}
If($userMatch)
{
# Process the data
$UserOutput += New-Object PsObject -Property @{ID =$name.usernames; "$col1" = $userMatch.$col1; "$col2" =$userMatch.$col2; "$col3" =$userMatch.$col3;"$col4" =$userMatch.$col4;"$col5" =$userMatch.$col5;"$col6" =$userMatch.$col6} #
}
else
{
$UserOutput += New-Object PsObject -Property @{ID =$name.usernames; "$col1" ="NA";"$col2" ="NA";"$col3" ="NA";"$col4" ="NA";"$col5" ="NA";"$col6" ="NA"}
}
}
$UserOutput | Select-Object "ID","$col1","$col2","$col3","$col4","$col5","$col6" | Export-Csv -Path $Result -NoTypeInformation
sleep -Milliseconds 200
[System.Windows.Forms.Application]::DoEvents()
if($script:CancelLoop -eq $true)
{
$progressbar1.Value = 0
break;
}
r
$progressbar1.PerformStep()
}
$this.Enabled = $true
$buttonCancelProcess.Enabled = $false
}
目前我有一堆文本框,我必须手动输入标题。我想消除它,并有一个生成的复选框列表,当一个框被检查,我点击“$ buttonstartprocess”它将从复选框中提取这些选项,并给我我想要的行。希望我不要失去任何人。再次感谢。
答案 0 :(得分:0)
这样的东西?
#get list of header
$headerlist=import-csv C:\temp\resul2.csv | Get-member -MemberType 'NoteProperty' | Select-Object -ExpandProperty 'Name'
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#create form
$Form = New-Object System.Windows.Forms.Form
$Form.Size = New-Object System.Drawing.Size(600,400)
$Form.text ="Form test"
#create groupbox for list checkbox
$groupBox = New-Object System.Windows.Forms.GroupBox
$groupBox.Location = New-Object System.Drawing.Size(240,20)
$groupBox.text = "You checkbox items"
$Form.Controls.Add($groupBox)
$Checkboxes += New-Object System.Windows.Forms.CheckBox
$Checkboxes.Location = New-Object System.Drawing.Size(10,20)
#add checkbox list
$Checkboxes = @()
$y = 20
foreach ($a in $headerlist)
{
$Checkbox = New-Object System.Windows.Forms.CheckBox
$Checkbox.Text = $a
$Checkbox.Location = New-Object System.Drawing.Size(10,$y)
$y += 30
$groupBox.Controls.Add($Checkbox)
$Checkboxes += $Checkbox
}
$groupBox.size = New-Object System.Drawing.Size(200,(40*$checkboxes.Count))
#show result
$form.ShowDialog()| Out-Null