Project

PSWriteOffice

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

Stars 654
Forks 82
Open issues 1
Total downloads 4,320,051
Release OfficeIMO-v3.5.3
Language: C# Updated: 2026-11-03
Cmdlet

Invoke-OfficeExcelTemplateOptionalRow

Aliases: ExcelTemplateOptionalRow, ExcelTemplateOptionalRows
Module
PSWriteOffice
Aliases
ExcelTemplateOptionalRow ExcelTemplateOptionalRows
Inputs
None
Outputs
System.Int32

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>]
#
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>]
#
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>]
#
Parameter set: Document

Examples

Keep an optional discount row and bind markers in it.

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.