API Reference

Cmdlet

Copy-OfficeExcelSheet

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

Copies a worksheet within a workbook or from another workbook.

Remarks

Copies a worksheet within a workbook or from another workbook.

Examples

Authored help example

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>]
#
Parameter set: Context

Parameters

CopyMode ExcelWorksheetCopyMode optionalposition: namedpipeline: Falsevalues: 2
Controls whether cross-workbook copies use package-level copy or value materialization.
Possible values: Values, Package
NewName String requiredposition: 2pipeline: Falsealiases: DestinationSheet, Name
Name for the copied worksheet.
SourceDocument ExcelDocument optionalposition: namedpipeline: False
Optional source workbook object for cross-workbook copies.
SourcePath String optionalposition: namedpipeline: False
Optional source workbook path for cross-workbook copies.
SourceSheet String optionalposition: 1pipeline: Falsealiases: Sheet, WorksheetName
Worksheet to copy. Defaults to the current sheet inside an ExcelSheet block.
ValidationMode SheetNameValidationMode optionalposition: namedpipeline: Falsevalues: 2
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>]
#
Parameter set: Path

Parameters

CopyMode ExcelWorksheetCopyMode optionalposition: namedpipeline: Falsevalues: 2
Controls whether cross-workbook copies use package-level copy or value materialization.
Possible values: Values, Package
InputPath String requiredposition: 0pipeline: Falsealiases: FilePath, Path
Target workbook path to update.
NewName String requiredposition: 2pipeline: Falsealiases: DestinationSheet, Name
Name for the copied worksheet.
SourceDocument ExcelDocument optionalposition: namedpipeline: False
Optional source workbook object for cross-workbook copies.
SourcePath String optionalposition: namedpipeline: False
Optional source workbook path for cross-workbook copies.
SourceSheet String optionalposition: 1pipeline: Falsealiases: Sheet, WorksheetName
Worksheet to copy. Defaults to the current sheet inside an ExcelSheet block.
ValidationMode SheetNameValidationMode optionalposition: namedpipeline: Falsevalues: 2
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>]
#
Parameter set: Document

Parameters

CopyMode ExcelWorksheetCopyMode optionalposition: namedpipeline: Falsevalues: 2
Controls whether cross-workbook copies use package-level copy or value materialization.
Possible values: Values, Package
Document ExcelDocument requiredposition: namedpipeline: True (ByValue)
Target workbook to update outside the DSL context.
NewName String requiredposition: 2pipeline: Falsealiases: DestinationSheet, Name
Name for the copied worksheet.
SourceDocument ExcelDocument optionalposition: namedpipeline: False
Optional source workbook object for cross-workbook copies.
SourcePath String optionalposition: namedpipeline: False
Optional source workbook path for cross-workbook copies.
SourceSheet String optionalposition: 1pipeline: Falsealiases: Sheet, WorksheetName
Worksheet to copy. Defaults to the current sheet inside an ExcelSheet block.
ValidationMode SheetNameValidationMode optionalposition: namedpipeline: Falsevalues: 2
Controls how invalid destination sheet names are handled.
Possible values: Sanitize, Strict

Outputs

OfficeIMO.Excel.ExcelSheet