Copy-OfficeExcelSheet
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>]#ContextCopy-OfficeExcelSheet
[-CopyMode <Values| Package>]
[-NewName] <String>
[-PassThru]
[-Path] <String>
[-SourceDocument <ExcelDocument>]
[-SourcePath <String>]
[[-SourceSheet] <String>]
[-ValidationMode <Sanitize| Strict>]
[<CommonParameters>]#PathCopy-OfficeExcelSheet
[-CopyMode <Values| Package>]
-Document <ExcelDocument>
[-NewName] <String>
[-PassThru]
[-SourceDocument <ExcelDocument>]
[-SourcePath <String>]
[[-SourceSheet] <String>]
[-ValidationMode <Sanitize| Strict>]
[<CommonParameters>]#DocumentExamples
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'
)
$proofCreates 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 IncomingRawCopies 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
- Controls whether cross-workbook copies use package-level copy or value materialization.
- Possible values:
Values,Package - -NewName String
- Name for the copied worksheet.
- -PassThru SwitchParameter
- Emit the object created or changed by the command.
- -SourceDocument ExcelDocument
- Optional source workbook object for cross-workbook copies.
- -SourcePath String
- Optional source workbook path for cross-workbook copies.
- -SourceSheet String
- Worksheet to copy. Defaults to the current sheet inside an ExcelSheet block.
- -ValidationMode ExcelSheetNameValidationMode
- Controls how invalid destination sheet names are handled.
- Possible values:
Sanitize,Strict - -Path String
- Target workbook path to update.
- -Document ExcelDocument
- 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.