API Reference
Copy-OfficeExcelSheet
Copies a worksheet within a workbook or from another workbook.
Remarks
Copies a worksheet within a workbook or from another workbook.
Examples
Copy a worksheet and confirm it exists.
PS>
$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.
PS>
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.
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.
Syntax
Copy-OfficeExcelSheet [-CopyMode <Values|Package>] -NewName <String> [-SourceDocument <ExcelDocument>] [-SourcePath <String>] [-SourceSheet <String>] [-ValidationMode <Sanitize|Strict>] [<CommonParameters>]#ContextParameters
- 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.
- 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 SheetNameValidationMode
- Controls how invalid destination sheet names are handled.
- Possible values:
Sanitize,Strict
Outputs
OfficeIMO.Excel.ExcelSheet
Copy-OfficeExcelSheet [-CopyMode <Values|Package>] -InputPath <String> -NewName <String> [-SourceDocument <ExcelDocument>] [-SourcePath <String>] [-SourceSheet <String>] [-ValidationMode <Sanitize|Strict>] [<CommonParameters>]#PathParameters
- CopyMode ExcelWorksheetCopyMode
- Controls whether cross-workbook copies use package-level copy or value materialization.
- Possible values:
Values,Package - InputPath String
- Target workbook path to update.
- NewName String
- Name for the copied worksheet.
- 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 SheetNameValidationMode
- Controls how invalid destination sheet names are handled.
- Possible values:
Sanitize,Strict
Outputs
OfficeIMO.Excel.ExcelSheet
Copy-OfficeExcelSheet [-CopyMode <Values|Package>] -Document <ExcelDocument> -NewName <String> [-SourceDocument <ExcelDocument>] [-SourcePath <String>] [-SourceSheet <String>] [-ValidationMode <Sanitize|Strict>] [<CommonParameters>]#DocumentParameters
- CopyMode ExcelWorksheetCopyMode
- Controls whether cross-workbook copies use package-level copy or value materialization.
- Possible values:
Values,Package - Document ExcelDocument
- Target workbook to update outside the DSL context.
- NewName String
- Name for the copied worksheet.
- 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 SheetNameValidationMode
- Controls how invalid destination sheet names are handled.
- Possible values:
Sanitize,Strict
Outputs
OfficeIMO.Excel.ExcelSheet