笔记
-
下面的代码是
PowerShell惯用等效于您问题中的VBA代码
; 它接受一个或多个工作簿的文本文件路径,可以作为直接参数,也可以通过
Get-ChildItem
管道输入。
-
这个这个
可以也可以不
坚持不懈
更改设置
为你。
-
在我基于Office 2019的测试中
关
默认情况下,但正在更改
坚持不懈
失败-无论是通过Excel GUI本身还是通过下面的函数。通过Excel GUI切换设置时,确实注册为“弄脏”工作簿,即需要
节省物
它在重新开放时又恢复到关闭状态。
function Disable-PageBreaks {
param(
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
[Alias('PSPath')]
[string[]] $LiteralPath
)
begin {
$xl = New-Object -ComObject Excel.Application
}
process {
& { # Run in a child scope, to auto-release the COM references.
foreach ($p in Convert-Path -LiteralPath $LiteralPath) {
if (-not $?) { return } # skip nonexistent files.
$wb = $xl.Workbooks.Open($LiteralPath)
foreach ($ws in $wb.Worksheets) {
$ws.DisplayPageBreaks = $false
}
$wb.Save()
$wb.Close()
}
}
}
end {
$xl.Quit()
$xl = $null
# Note: The excel.exe process should disappear after a few seconds.
}
}