powershell - 使用 Powershell 关闭特定的 Excel 文件

标签 powershell

用于终止特定 Excel 文件的适当 PowerShell cmdlet 是什么。命令

Stop-Process -Name "excel"

关闭所有打开的 Excel 应用程序。

提前致谢!

最佳答案

实际上,excel 在 excel.exe

的一个实例中打开 .xlsx 文件

杀死 excel.exe 将杀死所有打开的工作簿。 MainWindowTitle 仅显示事件工作簿,因此您将无法通过属性匹配被动工作簿。

关闭特定工作簿的更好方法是通过com对象获取excel实例。

关闭与Name(文件名)或FullName(文件路径)匹配的工作簿

$excel = [System.Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
$excel.DisplayAlerts = $false
$excel.Workbooks | %{if($_.Name -imatch "excel file name"){$_.Close()}}

关于powershell - 使用 Powershell 关闭特定的 Excel 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56454206/

相关文章:

windows - 将文件添加到文件夹时运行 .bat 文件的 Powershell 脚本

powershell - 您可以将私钥嵌入到 PowerShell WinSCP 脚本中吗?

具有 SharePoint 连接的 Azure 逻辑应用

powershell - Get-ChildItem 向资源管理器报告不同的值

powershell - 替换 CSV 第一列中的数据

windows - 如何从批处理文件运行 PowerShell 脚本

powershell - 使用开关触发命令

git - 适用于Windows Git Shell(PowerShell)的Github-如何在Git Shell和常规PowerShell之间 “sync settings”

c# - Powershell 等效于 C# List with Coordinates

powershell - mkdir 和 mkdir -p 之间的区别?