Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Invoke-OfficeExcelTemplate

Aliases: ExcelTemplate
Module
PSWriteOffice
Aliases
ExcelTemplate
Inputs
OfficeIMO.Excel.ExcelDocument System.Object

Fills {{Marker}} placeholders, repeats template rows or sheets, and keeps or removes optional rows.

Syntax

Invoke-OfficeExcelTemplate
[-Culture <CultureInfo>]
[-Document <ExcelDocument>]
[-MissingValueBehavior <PreserveMarker|EmptyString|Throw>]
[-PassThru]
[-Sheet <OfficeSheetSelector[]>]
[-ThrowOnMissing]
[-Value] <Hashtable>
[<CommonParameters>]
#
Parameter set: Values
Invoke-OfficeExcelTemplate
[-Culture <CultureInfo>]
[-Document <ExcelDocument>]
[-InputObject] <Object>
[-MissingValueBehavior <PreserveMarker|EmptyString|Throw>]
[-PassThru]
[-Sheet <OfficeSheetSelector[]>]
-TemplateRow <Int32>
[-ThrowOnMissing]
[<CommonParameters>]
#
Parameter set: Rows
Invoke-OfficeExcelTemplate
[-Culture <CultureInfo>]
[-Document <ExcelDocument>]
[-MissingValueBehavior <PreserveMarker|EmptyString|Throw>]
-OptionalRow <Int32>
[-PassThru]
[-Remove]
[-RowCount <Int32>]
[-Sheet <OfficeSheetSelector[]>]
[-ThrowOnMissing]
[-Value <Hashtable>]
[<CommonParameters>]
#
Parameter set: OptionalRows
Invoke-OfficeExcelTemplate
[-Culture <CultureInfo>]
[-Document <ExcelDocument>]
[-InputObject] <Object>
[-MissingValueBehavior <PreserveMarker|EmptyString|Throw>]
[-PassThru]
[-SheetNameProperty <String>]
-TemplateSheet <OfficeSheetSelector>
[-ThrowOnMissing]
[<CommonParameters>]
#
Parameter set: Sheets

Examples

Fill template markers

New-OfficeExcel -Path .\Reports\Service-Report-October.xlsx -Template .\Templates\Service-Report.xltx {
    ExcelTemplate @{ Client = 'Northwind Traders'; Month = 'October 2026'; Availability = 0.9994 }
}

Creates a report from a template and replaces its {{Client}}, {{Month}} and {{Availability}} markers.

Repeat a template row for each incident

$incidents = Import-OfficeCsv -Path .\Data\Incidents-October.csv
$values = @{
    Client       = 'Northwind Traders'
    Month        = 'October 2026'
    Availability = 0.9994
}
New-OfficeExcel -Path .\Reports\Service-Report-October.xlsx -Template .\Templates\Service-Report.xltx {
    ExcelTemplate $values -Culture en-GB
    ExcelSheet 'Report' {
        ExcelTemplate -TemplateRow 12 -InputObject $incidents
        ExcelTemplate -OptionalRow 18 -RowCount 3 -Remove
    }
}

Fills the header markers, repeats row 12 once per incident and removes the escalation block because nothing was escalated this month.

Create one sheet per site from a template sheet

$sites = Import-OfficeCsv -Path .\Facilities\Sites.csv
Open-OfficeExcel -Path .\Facilities\Inspections-2026.xlsx {
    ExcelTemplate -TemplateSheet Site -InputObject $sites -SheetNameProperty Name -ThrowOnMissing
}

Copies the Site template sheet once per site, names each copy after the site and fills its markers from the site record.

Parameters

-Culture CultureInfo optional
Culture used for value conversion and number-format presets.
-Document ExcelDocument optionalpipeline: True (ByValue)
Caller-owned workbook; omission uses the enclosing Excel content block.
-MissingValueBehavior ExcelTemplateMissingValueBehavior optional
Behavior used when a marker is not supplied by -Value.
Possible values: PreserveMarker, EmptyString, Throw
-PassThru SwitchParameter optional
Emits the native result after the operation.
-Sheet OfficeSheetSelector[] optionalsets: Values, Rows, OptionalRows
Worksheet name, one-based position or native worksheet object. Multi-sheet commands also accept wildcard names.
-ThrowOnMissing SwitchParameter optional
Throws when a marker is not supplied by -Value.
-Value Hashtable required in Valuesposition: 0sets: Values, OptionalRows
Value or values consumed by the selected operation.
-InputObject Object requiredposition: 1pipeline: True (ByValue)sets: Rows, Sheets
Objects, dictionaries or native tabular data supplied directly or through the pipeline.
-TemplateRow Int32 requiredsets: Rows
1-based row number that contains template markers to repeat.
-OptionalRow Int32 requiredsets: OptionalRows
Template row blocks whose visibility or inclusion is controlled by the supplied values.
-Remove SwitchParameter optionalsets: OptionalRows
Removes the optional row block instead of keeping and binding it.
-RowCount Int32 optionalsets: OptionalRows
Number of rows in the optional block.
-SheetNameProperty String optionalsets: Sheets
Input property used as the generated worksheet name.
-TemplateSheet OfficeSheetSelector requiredsets: Sheets
Template worksheet name. Defaults to the current sheet inside an ExcelSheet block or the first sheet for path/document use.

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.