Invoke-OfficeExcelTemplate
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>]#ValuesInvoke-OfficeExcelTemplate
[-Culture <CultureInfo>]
[-Document <ExcelDocument>]
[-InputObject] <Object>
[-MissingValueBehavior <PreserveMarker| EmptyString| Throw>]
[-PassThru]
[-Sheet <OfficeSheetSelector[]>]
-TemplateRow <Int32>
[-ThrowOnMissing]
[<CommonParameters>]#RowsInvoke-OfficeExcelTemplate
[-Culture <CultureInfo>]
[-Document <ExcelDocument>]
[-MissingValueBehavior <PreserveMarker| EmptyString| Throw>]
-OptionalRow <Int32>
[-PassThru]
[-Remove]
[-RowCount <Int32>]
[-Sheet <OfficeSheetSelector[]>]
[-ThrowOnMissing]
[-Value <Hashtable>]
[<CommonParameters>]#OptionalRowsInvoke-OfficeExcelTemplate
[-Culture <CultureInfo>]
[-Document <ExcelDocument>]
[-InputObject] <Object>
[-MissingValueBehavior <PreserveMarker| EmptyString| Throw>]
[-PassThru]
[-SheetNameProperty <String>]
-TemplateSheet <OfficeSheetSelector>
[-ThrowOnMissing]
[<CommonParameters>]#SheetsExamples
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
- Culture used for value conversion and number-format presets.
- -Document ExcelDocument
- Caller-owned workbook; omission uses the enclosing Excel content block.
- -MissingValueBehavior ExcelTemplateMissingValueBehavior
- Behavior used when a marker is not supplied by -Value.
- Possible values:
PreserveMarker,EmptyString,Throw - -PassThru SwitchParameter
- Emits the native result after the operation.
- -Sheet OfficeSheetSelector[]
- Worksheet name, one-based position or native worksheet object. Multi-sheet commands also accept wildcard names.
- -ThrowOnMissing SwitchParameter
- Throws when a marker is not supplied by -Value.
- -Value Hashtable
- Value or values consumed by the selected operation.
- -InputObject Object
- Objects, dictionaries or native tabular data supplied directly or through the pipeline.
- -TemplateRow Int32
- 1-based row number that contains template markers to repeat.
- -OptionalRow Int32
- Template row blocks whose visibility or inclusion is controlled by the supplied values.
- -Remove SwitchParameter
- Removes the optional row block instead of keeping and binding it.
- -RowCount Int32
- Number of rows in the optional block.
- -SheetNameProperty String
- Input property used as the generated worksheet name.
- -TemplateSheet OfficeSheetSelector
- 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.