Copy-ExcelWorkSheet.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function Copy-ExcelWorkSheet {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory=$true)]
        $SourceWorkbook,
        [Parameter(Mandatory=$true)]
        $SourceWorkSheet,
        [Parameter(Mandatory=$true)]
        $DestinationWorkbook,
        $DestinationWorkSheet,
        [Switch]$Show
    )

    Write-Verbose "Copying $($SourceWorkSheet) from $($SourceWorkbook) to $($DestinationWorkSheet) in $($DestinationWorkbook)"

    if(!$DestinationWorkSheet) {
        $DestinationWorkSheet = $SourceWorkSheet
    }

    Import-Excel -Path $SourceWorkbook -WorkSheetname $SourceWorkSheet |
        Export-Excel -Path $DestinationWorkbook -WorkSheetname $DestinationWorkSheet -Show:$Show
}