Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Invoke-OfficeExcelTemplate

Aliases: ExcelTemplate, ExcelTemplateApply
Module PSWriteOffice
Aliases
ExcelTemplate ExcelTemplateApply
Inputs
OfficeIMO.Excel.ExcelDocument
Outputs
System.Int32

Applies Excel template markers such as {{Name}} to one or more worksheets.

Syntax

Invoke-OfficeExcelTemplate [-CultureName <String>] [-MissingValueBehavior <PreserveMarker|EmptyString|Throw>] [-PassThru] [-Sheet <String>] [-SheetIndex <Int32>] [-ThrowOnMissing] -Value <Hashtable> [<CommonParameters>]
#
Parameter set: Context
Invoke-OfficeExcelTemplate [-CultureName <String>] [-MissingValueBehavior <PreserveMarker|EmptyString|Throw>] [-PassThru] [-Path] <String> [-Sheet <String>] [-SheetIndex <Int32>] [-ThrowOnMissing] -Value <Hashtable> [<CommonParameters>]
#
Parameter set: Path
Invoke-OfficeExcelTemplate [-CultureName <String>] -Document <ExcelDocument> [-MissingValueBehavior <PreserveMarker|EmptyString|Throw>] [-PassThru] [-Sheet <String>] [-SheetIndex <Int32>] [-ThrowOnMissing] -Value <Hashtable> [<CommonParameters>]
#
Parameter set: Document

Examples

Authored help example

Fill a workbook template from a hashtable.

Invoke-OfficeExcelTemplate -Path .\Invoice.xlsx -Sheet Invoice -Value @{ Number = 'INV-001'; Total = 123.45 } -CultureName en-US

Replaces matching template markers and saves the workbook.

Parameters

-CultureName String optional
Culture name used for built-in marker format aliases such as currency and date.
-MissingValueBehavior ExcelTemplateMissingValueBehavior optional
Behavior used when a marker is not supplied by -Value.
Possible values: PreserveMarker, EmptyString, Throw
-PassThru SwitchParameter optional
Returns the number of marker replacements.
-Sheet String optional
Worksheet name to update. Defaults to the current DSL sheet or all workbook sheets.
-SheetIndex Int32 optional
Worksheet index (0-based) to update. Defaults to the current DSL sheet or all workbook sheets.
-ThrowOnMissing SwitchParameter optional
Throws when a marker is not supplied by -Value.
-Value Hashtable requiredaliases: Values
Template marker values keyed by marker name.
-Path String requiredposition: 0aliases: FilePath, InputPathsets: Path
Workbook path to update.
-Document ExcelDocument requiredpipeline: True (ByValue)sets: 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.