Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Join-OfficeExcelWorkbook

Aliases: ExcelWorkbookJoin, ExcelWorkbookMerge, Merge-OfficeExcelWorkbook
Module PSWriteOffice
Aliases
ExcelWorkbookJoin ExcelWorkbookMerge Merge-OfficeExcelWorkbook
Inputs
OfficeIMO.Excel.ExcelDocument System.String[]
Outputs
OfficeIMO.Excel.ExcelWorkbookMergeResult

Merges worksheets from one or more workbooks into a target workbook.

Syntax

Join-OfficeExcelWorkbook [-CopyMode <Values|Package>] [-Path] <String> [-SheetNamePrefix <String>] [-SourceDocument <ExcelDocument>] [[-SourcePath] <String[]>] [-SourceSheet <String[]>] [-ValidationMode <Sanitize|Strict>] [<CommonParameters>]
#
Parameter set: Path
Join-OfficeExcelWorkbook [-CopyMode <Values|Package>] -Document <ExcelDocument> [-SheetNamePrefix <String>] [-SourceDocument <ExcelDocument>] [[-SourcePath] <String[]>] [-SourceSheet <String[]>] [-ValidationMode <Sanitize|Strict>] [<CommonParameters>]
#
Parameter set: Document

Examples

Authored help example

Merge workbook sheets using the package fast path.

$sources = Get-ChildItem .\Incoming\*.xlsx | Select-Object -ExpandProperty FullName
$results = Join-OfficeExcelWorkbook -Path .\Combined.xlsx -SourcePath $sources -CopyMode Package -SheetNamePrefix Import
$results | Select-Object SheetCount, SourceSheets, TargetSheets

Copies worksheets between packages without importing rows into PowerShell objects, which is the preferred path for large workbook merge workflows.

Import selected source sheets with a prefix.

$merge = Join-OfficeExcelWorkbook -Path .\Target.xlsx -SourcePath .\Source.xlsx -SourceSheet Data,Summary -SheetNamePrefix 'Imported '
Get-OfficeExcelSummary -Path .\Target.xlsx |
    Select-Object Path, WorksheetCount

Copies selected worksheets from Source.xlsx into Target.xlsx using OfficeIMO workbook merge logic.

Parameters

-CopyMode ExcelWorksheetCopyMode optional
Controls whether cross-workbook copies use package-level copy or value materialization.
Possible values: Values, Package
-Path String requiredposition: 0aliases: FilePath, InputPath, OutputPathsets: Path
Target workbook path to create or update.
-SheetNamePrefix String optional
Prefix added to every imported worksheet name.
-SourceDocument ExcelDocument optional
Optional source workbook object.
-SourcePath String[] optionalposition: 1pipeline: True (ByPropertyName)aliases: FullName, LiteralPath
Source workbook paths to merge into the target workbook.
-SourceSheet String[] optionalaliases: Sheet, SheetName, WorksheetName
Specific source worksheet names to import. Defaults to all source sheets.
-ValidationMode ExcelSheetNameValidationMode optional
Controls how invalid or duplicate destination sheet names are handled.
Possible values: Sanitize, Strict
-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.