Excel 워크 시트를 PowerShell으로 한 통합 문서로 복사하십시오.
-
14-09-2020 - |
문제
한 통합 문서에서 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?
. 해결책
게시물 kiron
인덱스가 두 번째 시트로 복사 할 수 있습니다.
$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
. 제휴하지 않습니다 StackOverflow