В прошлом я использовал этот код Power Shell для разделения книги Excel на несколько книг. Код работал в прошлом. Однако сейчас я получаю сообщение об ошибке.
командлет New-Object в позиции командного конвейера 1 Задайте значения для
следующие параметры:
TypeName:
Что не так с этим скриптом?
Function Get-FileName
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$SaveFileDialog = New-Object
System.Windows.Forms.OpenFileDialog
$SaveFileDialog.filter = "Excel Files (*.xls,*.xlsx)|*.xls;*.xlsx|All files (*.*)|*.*"
$SaveFileDialog.ShowDialog() | Out-Null
$SaveFileDialog.filename
}
Function Get-FolderName()
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$OpenFileDialog = New-Object
System.Windows.Forms.FolderBrowserDialog
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.SelectedPath
}
#Get filename to save results to from dialog
$filename = Get-FileName
$outputfolder = Get-FolderName
if($filename -eq "" -or $outputfolder -eq "")
{
break;
}
cls
Write-Host Parser running, please do not work with Excel while this is running...
#Open Report
$xl=New-Object -COM Excel.Application
$wb = $xl.Workbooks.Open($filename)
$xl.DisplayAlerts = $false
$xl.Visible = $false
$wsAct = $wb.worksheets.Item(1)
$wsAct.activate()
$RowCnt = $wsAct.UsedRange.Rows.Count
$CurPerson = ""
$PrevPerson = "prev"
$NewWBOpen = $false
for($index=2; $index -le $RowCnt; $index++)
{
cls
$out = "Processing Row " + $index + " of " + $RowCnt
$CurPerson = $wsAct.Cells($index,3).Value2 #3 references the column we want to index by.
$out
$CurPerson
if($CurPerson -ne $PrevPerson)
{
#Determine if there was a WB open that needs saved
if($NewWBOpen -eq $true)
{
#Save OpenWB before creating a new one
$fileName1 = $outputfolder + "\" + $svFileName
$wb2.SaveAs($fileName1)
$wb2.Close()
}
#Create new WB with header row
$wb2 = $xl.Workbooks.Add()
$wsAct2 = $wb2.Worksheets.Item(1)
#$wb2.Colors() = $wb.Colors()
$headerRange = $wsAct.Range("A1").EntireRow
$headerRange.Copy()|out-null
$HeaderRange = $wsAct2.Range("A1")
$wsAct2.Paste($headerRange)
#Add record to new WB
$cellRange = $wsAct.Cells($index,1).EntireRow
$cellRange.Copy()|out-null
$CellRange = $wsAct2.Range("A2")
$wsAct2.Paste($cellRange)
$NewWBOpen = $true
}
else
{
#Add to open WB
$RowCnt1 = $wsAct2.UsedRange.Rows.Count + 1
$cellRange = $wsAct.Cells($index,1).EntireRow
$cellRange.Copy()|out-null
$CellRange = $wsAct2.Range("A" + $RowCnt1)
$wsAct2.Paste($cellRange)
}
$PrevPerson = $CurPerson
$svFileName = $wsAct.Cells($index,2).Value2
#will use this index to create the file name
}
#Save OpenWB for last person
$fileName1 = $outputfolder + "\" + $svFileName
$wb2.SaveAs($fileName1)
$wb2.Close()
$wb.Close
$xl.Quit()
cls
Write-Host Database Parsing Complete!
Когда я запускаю код, я получаю сообщение об ошибке ниже. Что мне нужно сделать, чтобы исправить скрипт?
![enter image description here](https://i.stack.imgur.com/Cfsgn.png)