У меня есть несколько превосходных рабочих книг со скрытыми вкладками в них. Я хочу, чтобы эти вкладки оставались скрытыми, но я также хочу получить к ним доступ с помощью скрипта PowerShell. Тем не менее, мой сценарий, кажется, игнорирует эти таблицы, спрятанные в Excel. Я посмотрел в com объекты и не могу найти свойство для этого. Я попытался использовать $ excel.visible = $ true, но это, кажется, совершенно отдельно, плюс элементы, которые не видны, обычно доступны Powershell. Я хочу знать, есть ли способ программно получить доступ к этим скрытым вкладкам. Если мне нужно сделать их видимыми, то снова невидимыми, что сработает, но я хочу, чтобы они оставались скрытыми как обычно. Кто-нибудь знает способ сделать это?
$ErrorActionPreference = "Stop"
cd "P:\ANG_System_Files"
function Add-MissingVendor
{
param([PSCustomObject]$TypeOfVendors, [string]$excel_file_path)
$standardDifferences = Compare-Object -ReferenceObject $TypeOfVendors.VendorName -DifferenceObject $MainVendors.VendorName -PassThru
foreach ($difference in $standardDifferences)
{
$Excel1 = New-Object -ComObject Excel.Application
$ExcelWorkBookMain = $Excel1.Workbooks.Open("P:\ANG_System_Files\commonFormsUsedInScripts\Vendors.xlsx")
$ExcelWorkSheetMain = $ExcelWorkBookMain.WorkSheets.item("VendorList")
$ExcelWorkSheetMain.activate() | Out-Null
$ExcelWorkSheetMain.Visible = $true
$Found = $ExcelWorkSheetMain.Cells.Find($difference)
$foundDifference = $ExcelWorkSheetMain.Rows($($Found.Row))
$Excel2 = New-Object -ComObject Excel.Application
$ExcelWorkBookUpdate = $Excel2.Workbooks.Open($excel_file_path)
$ExcelWorkSheetUpdate = $ExcelWorkBookUpdate.WorkSheets.item("VendorList")
$ExcelWorkSheetUpdate.activate() | Out-Null
$ExcelWorkSheetUpdate.Visible = $true
$vendorName = $($foundDifference.Cells[1].Value2)
$contactName = $($foundDifference.Cells[2].Value2)
$vendorAddress = $($foundDifference.Cells[3].Value2)
$vendorCityState = $($foundDifference.Cells[4].Value2)
$vendorPhone = $($foundDifference.Cells[5].Value2)
$vendorEmail = $($foundDifference.Cells[6].Value2)
$row = $($Excel2.ActiveSheet.UsedRange.Rows)[-1].Row + 1
$ExcelWorkSheetUpdate.Cells.Item($row,1) = $vendorName
$ExcelWorkSheetUpdate.Cells.Item($row,2) = $contactName
$ExcelWorkSheetUpdate.Cells.Item($row,3) = $vendorAddress
$ExcelWorkSheetUpdate.Cells.Item($row,4) = $vendorCityState
$ExcelWorkSheetUpdate.Cells.Item($row,5) = $vendorPhone
$ExcelWorkSheetUpdate.Cells.Item($row,6) = $vendorEmail
$sortRange = $ExcelWorkSheetUpdate.UsedRange
$sortRange.Sort
$ExcelWorkBookUpdate.Save()
$ExcelWorkBookUpdate.Close()
$ExcelWorkBookMain.Close()
$Excel1.Quit()
$Excel2.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($Excel1)
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($Excel2)
}
}
$MainVendors = (Import-Excel -Path "P:\ANG_System_Files\commonFormsUsedInScripts\Vendors.xlsx" -WorksheetName "VendorList")
$StandardVendors = (Import-Excel -Path "P:\ANG_System_Files\commonFormsUsedInScripts\ANGstandardPO form-master.xlsx" -WorksheetName "VendorList")
$GlassVendors = (Import-Excel -Path "P:\ANG_System_Files\commonFormsUsedInScripts\ANGglassPO form-master.xlsx" -WorksheetName "VendorList")
$ViraconVendors = (Import-Excel -Path "P:\ANG_System_Files\commonFormsUsedInScripts\ANGviraconPO form-master.xlsx" -WorksheetName "VendorList")
Add-MissingVendor -TypeOfVendor $StandardVendors -excel_file_path "P:\ANG_System_Files\commonFormsUsedInScripts\ANGstandardPO form-master.xlsx"
Add-MissingVendor -TypeOfVendor $GlassVendors -excel_file_path "P:\ANG_System_Files\commonFormsUsedInScripts\ANGglassPO form-master.xlsx"
Add-MissingVendor -TypeOfVendor $ViraconVendors -excel_file_path "P:\ANG_System_Files\commonFormsUsedInScripts\ANGviraconPO form-master.xlsx"