Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Merge-OfficeExcelSheet

Module
PSWriteOffice
Inputs
OfficeIMO.Excel.ExcelDocument System.String[]
Outputs
OfficeIMO.Excel.ExcelWorksheetMergeResult

Appends worksheet rows or merges a source range into a target worksheet.

Syntax

Merge-OfficeExcelSheet
[-Address <String>]
[-BlankRowsBefore <Int32>]
[-Document <ExcelDocument>]
[-HeaderRow <Int32>]
[-IncludeSourceHeader]
[-MatchColumnsByHeader]
[-NoSourceHeader]
[-OverwriteExistingCells]
[-Sheet <OfficeSheetSelector>]
[-Source <Object>]
[-SourceRange <String>]
-SourceSheet <OfficeSheetSelector>
[<CommonParameters>]
#
Parameter set: Document
Merge-OfficeExcelSheet
[-Address <String>]
[-BlankRowsBefore <Int32>]
[-HeaderRow <Int32>]
[-IncludeSourceHeader]
[-MatchColumnsByHeader]
[-NoSourceHeader]
[-OverwriteExistingCells]
[-Path] <String[]>
[-Sheet <OfficeSheetSelector>]
[-Source <Object>]
[-SourceRange <String>]
-SourceSheet <OfficeSheetSelector>
[<CommonParameters>]
#
Parameter set: Path
Merge-OfficeExcelSheet
[-Address <String>]
[-BlankRowsBefore <Int32>]
[-HeaderRow <Int32>]
[-IncludeSourceHeader]
-LiteralPath <String[]>
[-MatchColumnsByHeader]
[-NoSourceHeader]
[-OverwriteExistingCells]
[-Sheet <OfficeSheetSelector>]
[-Source <Object>]
[-SourceRange <String>]
-SourceSheet <OfficeSheetSelector>
[<CommonParameters>]
#
Parameter set: LiteralPath

Description

Source accepts a native ExcelDocument, a workbook path or FileInfo. Omit Source to copy rows within the target workbook. File targets are saved in place; live documents remain caller-owned and require an explicit save. The result reports the actual copied rows and columns.

Examples

Append monthly rows by their column headers.

Merge-OfficeExcelSheet -Path ./Sales.xlsx -Sheet Year -SourceSheet October -MatchColumnsByHeader

Merge a literal source file at a chosen target cell.

Get-Item -LiteralPath './Combined[1].xlsx' | Merge-OfficeExcelSheet -Sheet Combined -Source (Get-Item -LiteralPath './Branch[1].xlsx') -SourceSheet Sales -Address B5 -HeaderRow 4 -MatchColumnsByHeader

Parameters

-Address String optional
Gets or sets the target start cell; omission appends after the used range.
-BlankRowsBefore Int32 optional
Gets or sets blank rows before appended data; an explicit Address takes precedence.
-Document ExcelDocument optionalpipeline: True (ByValue)sets: Document
Gets or sets the live target workbook; omission uses the enclosing worksheet scope.
-HeaderRow Int32 optional
Gets or sets the one-based target header row used for matching columns.
-IncludeSourceHeader SwitchParameter optional
Gets or sets whether to copy the source header along with its data rows.
-MatchColumnsByHeader SwitchParameter optional
Gets or sets whether columns are aligned by header text rather than position.
-NoSourceHeader SwitchParameter optional
Gets or sets whether the first source row is data rather than a header.
-OverwriteExistingCells SwitchParameter optional
Gets or sets whether source values may replace existing target cells.
-Sheet OfficeSheetSelector optional
Gets or sets the target worksheet name, one-based position or native worksheet.
-Source Object optional
Gets or sets another workbook as a native ExcelDocument, path or literal FileInfo.
-SourceRange String optional
Gets or sets the source A1 range; omission copies its used range.
-SourceSheet OfficeSheetSelector required
Gets or sets the source worksheet name, one-based position or native worksheet.
-Path String[] requiredposition: 0pipeline: True (ByValue)sets: Path
Gets or sets target workbook paths with filesystem wildcard expansion.
-LiteralPath String[] requiredpipeline: True (ByPropertyName)aliases: FullName, PSPathsets: LiteralPath
Gets or sets literal target paths, including FileInfo.FullName and provider PSPath.

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.