iT邦幫忙

0

Use Powershell Autofilter Excel by multiple column

  • 分享至 

  • xImage

$Filename = "檔案路徑"
$Excel = New-Object -ComObject Excel.Application
$Excel.DisplayAlerts = $false
$Workbook = $Excel.Workbooks.Open($Filename)
$Excel.Visible = $True
$Worksheet1 = $Workbook.Worksheets.item(1)
$Worksheet1.Select()

$xlFilterValues = 7 # found in MS documentation
$FL = @("未審核","已審核", "已取消")
$Range = $Worksheet1.cells.item(1,10).entirecolumn
$Range.select | Out-Null
$Excel.Selection.AutoFilter(7,$FL,$xlFilterValues))

想要使用powershell篩選Excel表 列J1 ,顯示未審核、已審核、已取消
但都會顯示無法取得類別Range的AutoFilter屬性

無法取得類別 Range 的 AutoFilter 屬性
位於 線路:13 字元:1

  • $Excel.Selection.AutoFilter(7,$FL,$xlFilterValues)
  •   + CategoryInfo          : OperationStopped: (:) [], COMException
      + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
    
    

參考文章:https://stackoverflow.com/questions/22497502/powershell-script-to-filter-a-particular-item-in-excel

https://social.msdn.microsoft.com/Forums/office/en-US/81e4a2b0-d016-4a56-92e6-c3d4befa75db/powershell-excel-autofilter-on-multiple-items?forum=exceldev

請求支援

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答