Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Merge-OfficeDocument

Module
PSWriteOffice
Inputs
System.IDisposable System.String[]
Outputs
System.IO.FileInfo OfficeIMO.Word.WordDocument OfficeIMO.Excel.ExcelDocument

Combines documents of the same native format in input order.

Syntax

Merge-OfficeDocument
[-NoClobber]
[-Options <Object[]>]
[-OutputPath] <String>
[-PassThru]
[-Password <SecureString[]>]
[-Path] <String[]>
[-Show]
[<CommonParameters>]
#
Parameter set: Path
Merge-OfficeDocument
[-Document] <IDisposable>
[-NoClobber]
[-Options <Object[]>]
[[-OutputPath] <String>]
[-PassThru]
[-Password <SecureString[]>]
[-Path] <String[]>
[<CommonParameters>]
#
Parameter set: Document
Merge-OfficeDocument
-LiteralPath <String[]>
[-NoClobber]
[-Options <Object[]>]
[-OutputPath] <String>
[-PassThru]
[-Password <SecureString[]>]
[-Show]
[<CommonParameters>]
#
Parameter set: LiteralPath

Description

Supports PDF and Open XML Word and Excel files. Binary projection and conversion are not performed. Word and Excel live documents can receive appended files and remain caller-owned. PDF merging creates a new document, so live PDF targets are not supported. PassThru returns a saved FileInfo for file input or the live document for Document input. Native merge options determine which content is imported.

Examples

Combine PDFs in the specified order.

Merge-OfficeDocument -Path ./agenda.pdf, ./minutes.pdf -OutputPath ./board-pack.pdf -PassThru

Combine Word files in pipeline order.

Get-ChildItem ./weekly -Filter *.docx | Sort-Object Name | Merge-OfficeDocument -OutputPath ./monthly.docx

Append files to a caller-owned proposal.

Merge-OfficeDocument -Document $proposal -Path ./scope.docx, ./pricing.docx -OutputPath ./proposal.docx

Parameters

-NoClobber SwitchParameter optional
Refuse to replace an existing destination; requires OutputPath.
-Options Object[] optional
Native merge settings, New-OfficeExcelMergeOptions results, or property hashtables for the selected format.
-OutputPath String required in Path, LiteralPathposition: 1
Destination with the same extension as every input; optional for a live document.
-PassThru SwitchParameter optional
Emit the saved FileInfo, or the caller-owned live document for Document input.
-Password SecureString[] optional
One source password reused for all files, or one password per resolved file in order; use $null for an unencrypted file in a per-file list.
-Path String[] requiredposition: 0pipeline: True (ByValue)sets: Path, Document
Files in merge order, or files appended to Document; wildcard matches retain provider order.
-Show SwitchParameter optionalsets: Path, LiteralPath
Open the saved result through the shell after successful publication.
-Document IDisposable requiredposition: 0pipeline: True (ByValue)sets: Document
A single editable Word or Excel document to append to; ownership stays with the caller.
-LiteralPath String[] requiredpipeline: True (ByPropertyName)aliases: FullName, PSPathsets: LiteralPath
Literal files in merge order, including FileInfo.FullName and provider PSPath properties.

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.