# Invoke-OfficeExcelTemplate

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

Cmdlet 

Aliases: ExcelTemplate

**Module**

`PSWriteOffice`

**Aliases**

`ExcelTemplate`

**Inputs**

`OfficeIMO.Excel.ExcelDocument` `System.Object`

**Source**

[InvokeOfficeExcelTemplateCommand.cs:49](https://github.com/EvotecIT/OfficeIMO/blob/be6c300e4ab1859837b961c64fbfb2b2a1886cd0/PowerShell/PSWriteOffice/Sources/PSWriteOffice/Cmdlets/Excel/InvokeOfficeExcelTemplateCommand.cs#L49) 

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>]
```

[#](#method-invoke-officeexceltemplate-cultureinfo-exceldocument-exceltemplatemissingvaluebehavior-switchparameter-officesheetselector-switchparameter-hashtable)

Parameter set: `Values`

```
Invoke-OfficeExcelTemplate
[-Culture <CultureInfo>]
[-Document <ExcelDocument>]
[-InputObject] <Object>
[-MissingValueBehavior <PreserveMarker|EmptyString|Throw>]
[-PassThru]
[-Sheet <OfficeSheetSelector[]>]
-TemplateRow <Int32>
[-ThrowOnMissing]
[<CommonParameters>]
```

[#](#method-invoke-officeexceltemplate-cultureinfo-exceldocument-object-exceltemplatemissingvaluebehavior-switchparameter-officesheetselector-int32-switchparameter)

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>]
```

[#](#method-invoke-officeexceltemplate-cultureinfo-exceldocument-exceltemplatemissingvaluebehavior-int32-switchparameter-switchparameter-int32-officesheetselector-switchparameter-hashtable)

Parameter set: `OptionalRows`

```
Invoke-OfficeExcelTemplate
[-Culture <CultureInfo>]
[-Document <ExcelDocument>]
[-InputObject] <Object>
[-MissingValueBehavior <PreserveMarker|EmptyString|Throw>]
[-PassThru]
[-SheetNameProperty <String>]
-TemplateSheet <OfficeSheetSelector>
[-ThrowOnMissing]
[<CommonParameters>]
```

[#](#method-invoke-officeexceltemplate-cultureinfo-exceldocument-object-exceltemplatemissingvaluebehavior-switchparameter-string-officesheetselector-switchparameter)

Parameter set: `Sheets`

## Examples

### Fill template markers

```powershell
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

```powershell
$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

```powershell
$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](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_commonparameters).

<!-- PowerForge markdown artifact sha256:8652D03CECB59C8E4548B8B3944760FC75AF47588208EF79BE410E7F0AC2063C -->
