PowerShell + Excel-$ workbook.save()挂在我身上 [英] PowerShell + Excel - $workbook.save() hangs up on me
问题描述
我开始在PowerShell上使用Excel,这是因为我必须遍历138个文件,将每个 $ B $ 1
实例更改为 TEXT($ B $ 1,"0000")
,而我不想手动操作.
I started messing around with Excel on PowerShell, specially because I had to go through 138 files changing every instance of $B$1
to TEXT($B$1,"0000")
and I didn't want to do that manually.
在线找到了一些资源并更改了公式,但是当我尝试 .Save()
时,PowerShell似乎只是坐在那里,等待着我不知道的东西.
Found a couple of resources online and changed the formula but when I try .Save()
, PowerShell seems to just sit there, waiting for something I have no idea what.
PS C:\> $excel = New-Object -com Excel.Application
PS C:\> Get-ChildItem '\\UNC\Path\to\folder' <Common file string>*.xls -Recurse | Select-Object -First 1 | % {
>> $workbook = $excel.Workbooks.Open($_.Fullname)
>> $workbook.Save()
>> }
关于可能是什么问题的任何想法?
Any ideas on what could be the problem?
推荐答案
当Excel在这方面挂起时,我怀疑它正在等待您做某事.最简单的是确认这是将可见性设置为True.
When Excel hangs in this regard I would suspect it is waiting for you to do something. The easiest was to confirm this is setting the visibility to True.
$excel.Visible = $true
这只会向您显示以前隐藏的对话框.正如评论中所讨论的,您似乎从兼容检查器收到了一条消息.一旦您知道它是什么并且愿意抑制它,那就拥有以下
That would just show you the dialog that was hidden from you previously. As discussed in comments it appears you got a message from the Compatibly Checker. Once you know what it is and are willing to suppress it then just have the following
$excel.Visible = $false
$excel.displayAlerts = $false
这篇关于PowerShell + Excel-$ workbook.save()挂在我身上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!