我正在尝试为创建XLSX
电子表格时创建进度条。我无法锻炼如何让它发挥作用。
以下是我的代码。
*更新了我的代码,这是我遇到的问题,我之前添加了整个代码以显示Ex的功能,但似乎不需要它。所以自定义创建的progess栏我想在执行Ex功能后显示给用户,该功能创建并更新excel电子表格,我希望它能实时更新用户关于Ex中每个阶段的进度,它遵循以下过程;
最后保存电子表格并关闭。
Add-Type -assembly System.Windows.Forms
## -- Create The Progress-Bar
$ObjForm = New-Object System.Windows.Forms.Form
$ObjForm.Text = "Finishing Process"
$ObjForm.Height = 100
$ObjForm.Width = 500
$ObjForm.BackColor = "White"
$ObjForm.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedSingle
$ObjForm.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen
## -- Create The Label
$ObjLabel = New-Object System.Windows.Forms.Label
$ObjLabel.Text = "Starting. Please wait ... "
$ObjLabel.Left = 5
$ObjLabel.Top = 10
$ObjLabel.Width = 500 - 20
$ObjLabel.Height = 15
$ObjLabel.Font = "Tahoma"
## -- Add the label to the Form
$ObjForm.Controls.Add($ObjLabel)
$PB = New-Object System.Windows.Forms.ProgressBar
$PB.Name = "PowerShellProgressBar"
$PB.Value = 0
$PB.Style="Continuous"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 500 - 40
$System_Drawing_Size.Height = 20
$PB.Size = $System_Drawing_Size
$PB.Left = 5
$PB.Top = 40
$ObjForm.Controls.Add($PB)
## -- Show the Progress-Bar and Start The PowerShell Script
$ObjForm.Show() | Out-Null
$ObjForm.Focus() | Out-NUll
$ObjLabel.Text = "Starting. Please wait ... "
$ObjForm.Refresh()
Start-Sleep -Seconds 1
Out-Null
## -- Execute The PowerShell Code and Update the Status of the Progress-Bar
$Ex = Ex
$Ex
$Counter = 0
ForEach ($Item In $Ex) {
## -- Calculate The Percentage Completed
$Counter++
[Int]$Percentage = ($Counter/$Ex.Count)*100
$PB.Value = $Percentage
$ObjLabel.Text = "Creating an Xlsx File Please wait"
#$ObjLabel.Text = "Found $counter $Criteria in $Search"
$ObjForm.Refresh()
Start-Sleep -Milliseconds 150
# -- $Item.Name
#"`t" + $Item.Path
}
$ObjForm.Close()