Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Copy-OfficeExcelSheet

Aliases: ExcelSheetCopy
Module PSWriteOffice
Aliases
ExcelSheetCopy
Inputs
OfficeIMO.Excel.ExcelDocument
Outputs
OfficeIMO.Excel.ExcelSheet

Copies a worksheet within a workbook or from another workbook.

Syntax

Copy-OfficeExcelSheet [-CopyMode <Values|Package>] [-NewName] <String> [-PassThru] [-SourceDocument <ExcelDocument>] [-SourcePath <String>] [[-SourceSheet] <String>] [-ValidationMode <Sanitize|Strict>] [<CommonParameters>]
#
Parameter set: Context
Copy-OfficeExcelSheet [-CopyMode <Values|Package>] [-NewName] <String> [-PassThru] [-Path] <String> [-SourceDocument <ExcelDocument>] [-SourcePath <String>] [[-SourceSheet] <String>] [-ValidationMode <Sanitize|Strict>] [<CommonParameters>]
#
Parameter set: Path
Copy-OfficeExcelSheet [-CopyMode <Values|Package>] -Document <ExcelDocument> [-NewName] <String> [-PassThru] [-SourceDocument <ExcelDocument>] [-SourcePath <String>] [[-SourceSheet] <String>] [-ValidationMode <Sanitize|Strict>] [<CommonParameters>]
#
Parameter set: Document

Examples

Authored help example

Copy a worksheet and confirm it exists.

$proof = @(
    Copy-OfficeExcelSheet -Path .\Report.xlsx -SourceSheet Data -NewName DataCopy
    Get-OfficeExcelSummary -Path .\Report.xlsx -IncludeSheets |
        Select-Object -ExpandProperty Sheets |
        Where-Object Name -eq 'DataCopy'
)
$proof

Creates a copy of the Data worksheet and reads the workbook summary to verify the new tab.

Copy a worksheet from another workbook using the package fast path.

Copy-OfficeExcelSheet -Path .\Combined.xlsx -SourcePath .\Incoming.xlsx -SourceSheet RawData -NewName IncomingRaw -CopyMode Package
Get-OfficeExcelUsedRange -Path .\Combined.xlsx -Sheet IncomingRaw

Copies the source worksheet package directly so large workbook merges avoid converting rows into PowerShell objects. Use CopyMode Values only when you explicitly want the reader/writer fallback.

Parameters

-CopyMode ExcelWorksheetCopyMode optional
Controls whether cross-workbook copies use package-level copy or value materialization.
Possible values: Values, Package
-NewName String requiredposition: 2aliases: DestinationSheet, Name
Name for the copied worksheet.
-PassThru SwitchParameter optional
Emit the object created or changed by the command.
-SourceDocument ExcelDocument optional
Optional source workbook object for cross-workbook copies.
-SourcePath String optional
Optional source workbook path for cross-workbook copies.
-SourceSheet String optionalposition: 1aliases: Sheet, WorksheetName
Worksheet to copy. Defaults to the current sheet inside an ExcelSheet block.
-ValidationMode ExcelSheetNameValidationMode optional
Controls how invalid destination sheet names are handled.
Possible values: Sanitize, Strict
-Path String requiredposition: 0aliases: FilePath, InputPathsets: Path
Target workbook path to update.
-Document ExcelDocument requiredpipeline: True (ByValue)sets: Document
Target workbook to update outside the DSL context.

Common Parameters

This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.

For more information, see about_CommonParameters.