gpt4 book ai didi

excel - 无法使用 PowerShell 在 excel 的第一行启用过滤器

转载 作者:行者123 更新时间:2023-12-04 22:13:59 24 4
gpt4 key购买 nike

在 Excel 文件上使用 powershell 启用自动过滤模式时出现错误。这是我正在尝试的脚本

$objExcel=New-Object -ComObject Excel.Application
$objExcel.Visible=$True
$workbook=$objExcel.Workbooks.Open('C:\Trash\filter.xlsx')
$worksheet = $workbook.worksheets | where {$_.name -eq 'sheet1'}
$worksheet.autofiltermode=$true


$workbook.Save()
$objExcel.Quit()
错误:
Unable to set the AutoFilterMode property of the Worksheet class
At line:1 char:1
+ $worksheet.autofiltermode=$true
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
这就是我所期待的(附件)
[1]: /image/X0DS8.png

最佳答案

供引用:
Worksheet.AutoFilterMode Property

RemarksYou can set this property to false to disable filtering (that is, to remove the filter drop-down arrows), but you cannot set it to true. To enable filtering and create a filtered list, use the AutoFilter method of a Range object, or use the AutoFilter method of a NamedRange object.

关于excel - 无法使用 PowerShell 在 excel 的第一行启用过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71185281/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com