Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在powershell中操作已在运行的excel实例_Excel_Powershell - Fatal编程技术网

在powershell中操作已在运行的excel实例

在powershell中操作已在运行的excel实例,excel,powershell,Excel,Powershell,好的,我打开了一个从powershell启动的Internet Explorer实例的工作簿,使用: $browser = new-object -ComObject "InternetExplorer.Application" $browser.navigate("url") 我从url下载/打开了工作簿,但我想使用正在运行的脚本对其进行操作。我想知道是否能够从进程id创建一个新的com对象: (Get-Process excel | Where-Object {$_.MainWindow

好的,我打开了一个从powershell启动的Internet Explorer实例的工作簿,使用:

$browser = new-object -ComObject "InternetExplorer.Application"
$browser.navigate("url")
我从url下载/打开了工作簿,但我想使用正在运行的脚本对其进行操作。我想知道是否能够从进程id创建一个新的com对象:

(Get-Process  excel | Where-Object {$_.MainWindowTitle  -like "*titleOFdownloadedEXCELwb*"}).id
有人能给我指出正确的方向吗?多谢各位

$xl = [Runtime.Interopservices.Marshal]::GetActiveObject('Excel.Ap‌​plication')

将以活动Excel实例(如果存在)为目标。

不要担心获取Excel实例。创建一个Excel.Application实例,它将自动为您提供一个正在运行的实例。将应用程序上的visible设置为true,然后使用app.workbooks集合枚举工作簿并查找您的工作簿感谢您的回复,问题是,工作簿是从浏览器(在临时文件夹中下载)打开的,然后在excel中打开的。如何枚举wb?
$xl=[Runtime.Interopservices.marshall]::GetActiveObject('Excel.Application')
谢谢你,dgorti和@sodawillow,我现在可以开始工作了。