gpt4 book ai didi

excel - 卡住工作表的顶行

转载 作者:行者123 更新时间:2023-12-02 14:08:21 24 4
gpt4 key购买 nike

PowerShell 代码创建 Excel。

我正在尝试卡住顶行:

$excel = New-Object -Com Excel.Application
$excel.Visible = $True
$wb = $Excel.Workbooks.Add()
$ws = $wb.Worksheets.Add()

$ws.Activate()
$ws.Select()

$excel.Rows.Item("1:1").Select()
$excel.ActiveWindow.FreezePanes = $true

它不是卡住顶行,而是卡住行中心和列中心,即

enter image description here

更新

重复帖子中的解决方案不起作用,即

$excel.Rows("1:1").Select()
$excel.ActiveWindow.FreezePanes = $true

出现以下错误:

Method invocation failed because [System.__ComObject] does not contain a method named 'Rows'.
At D:\Script\upgrades.ps1:231 char:5
+ $excel.Rows("1:1").Select()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Rows:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound

最佳答案

要卡住顶行,您需要选择第二行:

$excel.Rows.Item("2:2").Select()
$excel.ActiveWindow.FreezePanes = $true

关于excel - 卡住工作表的顶行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30357513/

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