2017-12-17 1 views
0

하나의 WS를 복사하거나 일부 범위를 복사하는 방법에 대한 몇 가지 게시물이 있지만, 전체 WS를 이미 기존 WS에 값으로 복사하는 방법 다른 통합 문서에서. 이것이 내가 시도한 것입니다 :값 복사 전체 워크 시트를 PowerShell로 다른 워크 시트에 복사

$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() 

그리고 분명히 작동하지 않습니다.

답변

0

콘텐츠를 복사하려는 경우 Worksheet 개체의 Copy() 메서드를 사용할 수 없습니다.

$wb_source.Sheets.Item($SourceSheet).Cells.Copy() 
$wb_target.Sheets.Item($TargetSheet).Cells.PasteSpecial(-4163) 
다음 Range 오브젝트 (특히 Cells 컬렉션)의 방법을 사용 Copy()
관련 문제