# Invoke-OfficeExcelTemplateOptionalRow

Includes or removes an optional Excel template row block.

Project

PSWriteOffice

PowerShell document automation across OfficeIMO's document, spreadsheet, presentation, PDF, Project, Access, EPUB, invoicing, and conversion engines.

[View on GitHub](https://github.com/EvotecIT/OfficeIMO/tree/master/PowerShell/PSWriteOffice) [Visit Website](#) [Releases](https://github.com/EvotecIT/PSWriteOffice/releases/tag/v3.0.5) [Changelog](#) [Get package](https://www.powershellgallery.com/packages/PSWriteOffice/0.2.0)

Stars **725**

Forks **84**

Open issues **3**

Total downloads **5,231,343**

Release **OfficeIMO-v3.6.2**

Language: C# Updated: 2026-11-23

Cmdlet 

Aliases: ExcelTemplateOptionalRow, ExcelTemplateOptionalRows

**Module**

`PSWriteOffice`

**Aliases**

`ExcelTemplateOptionalRow` `ExcelTemplateOptionalRows`

**Inputs**

`None`

**Outputs**

`System.Int32`

**Source**

[InvokeOfficeExcelTemplateOptionalRowCommand.cs:19](https://github.com/EvotecIT/PSWriteOffice/blob/main/Sources/PSWriteOffice/Cmdlets/Excel/InvokeOfficeExcelTemplateOptionalRowCommand.cs#L19) 

Includes or removes an optional Excel template row block.

## Syntax

```
Invoke-OfficeExcelTemplateOptionalRow
[-CultureName <String>]
-FirstRow <Int32>
[-MissingValueBehavior <PreserveMarker|EmptyString|Throw>]
[-PassThru]
[-Remove]
[-RowCount <Int32>]
[-Sheet <String>]
[-SheetIndex <Int32>]
[-ThrowOnMissing]
[-Value <Hashtable>]
[<CommonParameters>]
```

[#](#method-invoke-officeexceltemplateoptionalrow-string-int32-exceltemplatemissingvaluebehavior-switchparameter-switchparameter-int32-string-int32-switchparameter-hashtable)

Parameter set: `Context`

```
Invoke-OfficeExcelTemplateOptionalRow
[-CultureName <String>]
-FirstRow <Int32>
[-MissingValueBehavior <PreserveMarker|EmptyString|Throw>]
[-PassThru]
[-Path] <String>
[-Remove]
[-RowCount <Int32>]
[-Sheet <String>]
[-SheetIndex <Int32>]
[-ThrowOnMissing]
[-Value <Hashtable>]
[<CommonParameters>]
```

[#](#method-invoke-officeexceltemplateoptionalrow-string-int32-exceltemplatemissingvaluebehavior-switchparameter-string-switchparameter-int32-string-int32-switchparameter-hashtable)

Parameter set: `Path`

```
Invoke-OfficeExcelTemplateOptionalRow
[-CultureName <String>]
-Document <ExcelDocument>
-FirstRow <Int32>
[-MissingValueBehavior <PreserveMarker|EmptyString|Throw>]
[-PassThru]
[-Remove]
[-RowCount <Int32>]
[-Sheet <String>]
[-SheetIndex <Int32>]
[-ThrowOnMissing]
[-Value <Hashtable>]
[<CommonParameters>]
```

[#](#method-invoke-officeexceltemplateoptionalrow-string-exceldocument-int32-exceltemplatemissingvaluebehavior-switchparameter-switchparameter-int32-string-int32-switchparameter-hashtable)

Parameter set: `Document`

## Examples

### Keep an optional discount row and bind markers in it.

```powershell
Invoke-OfficeExcelTemplateOptionalRow -Path .\Invoice.xlsx -Sheet Invoice -FirstRow 10 -Value @{ Discount = '10%' }
```

Leaves the optional row block in place, replaces its markers, and saves the workbook.

## Parameters

**-CultureName String optional**

Culture name used for built-in marker format aliases such as currency and date.

**-FirstRow Int32 required**

1-based first row in the optional block.

**-MissingValueBehavior ExcelTemplateMissingValueBehavior optional**

Behavior used when a marker in the optional block is not supplied by -Value.

Possible values: `PreserveMarker`, `EmptyString`, `Throw`

**-PassThru SwitchParameter optional**

Returns the number of marker replacements.

**-Remove SwitchParameter optional**

Removes the optional row block instead of keeping and binding it.

**-RowCount Int32 optional**

Number of rows in the optional block.

**-Sheet String optional**

Worksheet name. Defaults to the current sheet inside an ExcelSheet block.

**-SheetIndex Int32 optional**

Worksheet index when using a workbook object or path.

**-ThrowOnMissing SwitchParameter optional**

Throws when a marker in the optional block is not supplied by -Value.

**-Value Hashtable optionalaliases: Values**

Template marker values used when the optional row block is included.

**-Path String requiredposition: 0aliases: FilePath, InputPathsets: Path**

Workbook path to update.

**-Document ExcelDocument requiredsets: Document**

Workbook to update outside the DSL context.

## 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).

Evotec API Reference Copyright 2026 Evotec Services

<!-- PowerForge markdown artifact sha256:CA373A032CB569D33A0C4BC10FCB14619AACE1F5E5BBA02F4934F88C1CB40E57 -->
