< Back

Copy-ExcelWorkSheet

Wed Jan 15, 2020 12:33 am

NAME Copy-ExcelWorkSheet



SYNOPSIS

Copies a worksheet between workbooks or within the same workbook.





SYNTAX

Copy-ExcelWorkSheet [-SourceObject] <Object> [[-SourceWorkSheet] <Object>] [-DestinationWorkbook] <Object>

[[-DestinationWorksheet] <Object>] [-Show] [<CommonParameters>]





DESCRIPTION

Copy-ExcelWorkSheet takes a Source object which is either a worksheet, or a package, Workbook or path, in which

case the source worksheet can be specified by name or number (starting from 1). The destination worksheet can be

explicitly named, or will follow the name of the source if no name is specified. The Destination workbook can be

given as the path to an XLSx file, an ExcelPackage object or an ExcelWorkbook object.





PARAMETERS

-SourceObject <Object>

An ExcelWorkbook or ExcelPackage object or the path to an XLSx file where the data is found.



Required? true

Position? 1

Default value None

Accept pipeline input? True (ByValue)

Accept wildcard characters? false



-SourceWorkSheet <Object>

Name or number (starting from 1) of the worksheet in the source workbook (defaults to 1).



Required? false

Position? 2

Default value 1

Accept pipeline input? False

Accept wildcard characters? false



-DestinationWorkbook <Object>

An ExcelWorkbook or ExcelPackage object or the path to an XLSx file where the data should be copied.



Required? true

Position? 3

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-DestinationWorksheet <Object>

Name of the worksheet in the destination workbook; by default the same as the source worksheet's name. If the

sheet exists it will be deleted and re-copied.



Required? false

Position? 4

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-Show [<SwitchParameter>]

if the destination is an excel package or a path, launch excel and open the file on completion.



Required? false

Position? named

Default value False

Accept pipeline input? False

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



NOTES









-------------------------- EXAMPLE 1 --------------------------



Copy-ExcelWorkSheet -SourceWorkbook Test1.xlsx -DestinationWorkbook Test2.xlsx



This is the simplest version of the command: no source worksheet is specified so Copy-ExcelWorksheet uses the

first sheet in the workbook No Destination sheet is specified so the new worksheet will be the same as the one

which is being copied.

-------------------------- EXAMPLE 2 --------------------------



Copy-ExcelWorkSheet -SourceWorkbook Server1.xlsx -sourceWorksheet "Settings" -DestinationWorkbook Settings.xlsx

-DestinationWorksheet "Server1"



Here the Settings page from Server1's workbook is copied to the 'Server1" page of a "Settings" workbook.

-------------------------- EXAMPLE 3 --------------------------



$excel = Open-ExcelPackage .\\test.xlsx



C:\\> Copy-ExcelWorkSheet -SourceWorkbook $excel -SourceWorkSheet "first" -DestinationWorkbook $excel -Show

-DestinationWorksheet Duplicate This opens the workbook test.xlsx and copies the worksheet named "first" to a new

worksheet named "Duplicate", because -Show is specified the file is saved and opened in Excel

-------------------------- EXAMPLE 4 --------------------------



$excel = Open-ExcelPackage .\\test.xlsx



C:\\> Copy-ExcelWorkSheet -SourceWorkbook $excel -SourceWorkSheet 1 -DestinationWorkbook $excel

-DestinationWorksheet Duplicate C:\\> Close-ExcelPackage $excel This is almost the same as the previous example,

except source sheet is specified by position rather than name and because -Show is not specified, so other steps

can be carried using the package object, at the end the file is saved by Close-ExcelPackage



RELATED LINKS





CommonParameters : False

WorkflowCommonParameters : False

details : @{name=DoChart; noun=; verb=}

Syntax : @{syntaxItem=System.Object[]}

parameters : @{parameter=System.Object[]}

inputTypes : @{inputType=}

returnValues : @{returnValue=}

aliases : None



remarks : None

alertSet :

description :

examples :

Synopsis :

DoChart [[-targetData] <Object>] [[-title] <Object>] [[-ChartType] <eChartType>]

[-NoLegend] [-ShowCategory] [-ShowPercent]



ModuleName : ImportExcel

nonTerminatingErrors :

xmlns:command : http://schemas.microsoft.com/maml/dev/command/2004/10

xmlns:dev : http://schemas.microsoft.com/maml/dev/2004/10

xmlns:maml : http://schemas.microsoft.com/maml/2004/10

Name : DoChart

Category : Function

Component :

Role :

Functionality :