Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.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
Com 使用Powershell将Excel工作表从一个工作簿复制到另一个工作簿_Com_Powershell_Excel_Office Automation_Vba - Fatal编程技术网

Com 使用Powershell将Excel工作表从一个工作簿复制到另一个工作簿

Com 使用Powershell将Excel工作表从一个工作簿复制到另一个工作簿,com,powershell,excel,office-automation,vba,Com,Powershell,Excel,Office Automation,Vba,我想使用Powershell将工作表从一个工作簿复制(或移动)到另一个工作簿 我以前做过,不记得是怎么做的。我想我使用了CopyTo()函数 只是为了开始 $missing = [System.Type]::missing $excel = New-Object -Com Excel.Application $wb1 = $excel.Workbooks.Add($missing) $wb2 = $excel.Workbooks.Add($missing) # Now, to copy wo

我想使用Powershell将工作表从一个工作簿复制(或移动)到另一个工作簿

我以前做过,不记得是怎么做的。我想我使用了CopyTo()函数

只是为了开始

$missing = [System.Type]::missing
$excel = New-Object -Com Excel.Application

$wb1 = $excel.Workbooks.Add($missing)
$wb2 = $excel.Workbooks.Add($missing)

# Now, to copy worksheet "Sheet3" from $wb2 into $wb1 as second worksheet.
# How?
基隆见

将索引更改为复制到第二张图纸:

$file1 = 'C:\Users\eric\Documents\Book1.xlsx' # source's fullpath
$file2 = 'C:\Users\eric\Documents\Book2.xlsx' # destination's fullpath
$xl = new-object -c excel.application
$xl.displayAlerts = $false # don't prompt the user
$wb2 = $xl.workbooks.open($file1, $null, $true) # open source, readonly
$wb1 = $xl.workbooks.open($file2) # open target
$sh1_wb1 = $wb1.sheets.item(2) # second sheet in destination workbook
$sheetToCopy = $wb2.sheets.item('Sheet3') # source sheet to copy
$sheetToCopy.copy($sh1_wb1) # copy source sheet to destination workbook
$wb2.close($false) # close source workbook w/o saving
$wb1.close($true) # close and save destination workbook
$xl.quit()
spps -n excel

除了我有一个问题外,一切正常。复制后,复制零件的目标图纸仍处于选定状态。我如何停用它?