已经有一些关于如何复制 - 移动一个WS或复制某些范围的帖子,但我感兴趣的是如何将整个WS作为值复制到其他工作簿中已存在的WS中。这就是我试过的:
$obj_excel = New-Object -ComObject Excel.Application
$obj_excel.DisplayAlerts = $false # don't prompt the user
# Open source and target files
$wb_source = $obj_excel.Workbooks.Open($SourceFile, $null, $true) # open source, readonly
$wb_target = $obj_excel.Workbooks.Open($TargetFile) # open target
[void]$wb_target.Sheets.Item($TargetSheet).Copy()
[void]$wb_source.Sheets.Item($SourceSheet).PasteSpecial(-4163)
$wb_source.Close($false) # close source workbook w/o saving
$wb_target.Close($true) # close and save destination workbook
$obj_excel.Quit()
它显然不起作用。