Project

PSWriteOffice

PowerShell document automation across Word, Excel, PowerPoint, PDF, Reader, Confluence, Visio, and open text formats.

Stars 159
Forks 14
PowerShell Gallery downloads 158,661
Release v3.0.5
Language: C# Updated: 2026-09-03

API Reference

Cmdlet

Add-OfficeExcelSheet

Aliases: ExcelSheet
Namespace PSWriteOffice
Aliases
ExcelSheet
Inputs
OfficeIMO.Excel.ExcelDocument
Outputs
OfficeIMO.Excel.ExcelSheet

Adds or reuses a worksheet within the current Excel DSL scope.

Remarks

Creates the sheet when missing, pushes it onto the DSL stack, and executes the nested script block.

Examples

Authored help example

Create a sheet named Data.

PS>


New-OfficeExcel -Path .\report.xlsx { Add-OfficeExcelSheet -Name 'Data' { ExcelCell -Address 'A1' -Value 'Region' } }
        

Creates a workbook with a worksheet named Data and writes the header “Region”.

Add a worksheet through the workbook pipeline.

PS>


$sheet = $workbook | Add-OfficeExcelSheet -Name 'Data' -PassThru
            $sheet | Set-OfficeExcelCell -Address A1 -Value 'Region'
        

Returns the worksheet so subsequent commands can target it directly.

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.

Syntax

Add-OfficeExcelSheet [-Content <ScriptBlock>] [-Name <String>] [-PassThru] [-ValidationMode <Sanitize|Strict>] [<CommonParameters>]
#
Parameter set: Context

Parameters

Content ScriptBlock optionalposition: 1pipeline: False
Code to execute inside the worksheet context.
Name String optionalposition: 0pipeline: False
Name of the worksheet to create or reuse. When omitted the last sheet is reused or a default sheet is created.
PassThru SwitchParameter optionalposition: namedpipeline: False
Emit the ExcelSheet object after execution.
ValidationMode ExcelSheetNameValidationMode optionalposition: namedpipeline: Falsevalues: 2
Controls how invalid sheet names are handled.
Possible values: Sanitize, Strict

Outputs

OfficeIMO.Excel.ExcelSheet

Add-OfficeExcelSheet [-Content <ScriptBlock>] -Document <ExcelDocument> [-Name <String>] [-PassThru] [-ValidationMode <Sanitize|Strict>] [<CommonParameters>]
#
Parameter set: Document

Parameters

Content ScriptBlock optionalposition: 1pipeline: False
Code to execute inside the worksheet context.
Document ExcelDocument requiredposition: namedpipeline: True (ByValue)
Workbook that will receive the worksheet.
Name String optionalposition: 0pipeline: False
Name of the worksheet to create or reuse. When omitted the last sheet is reused or a default sheet is created.
PassThru SwitchParameter optionalposition: namedpipeline: False
Emit the ExcelSheet object after execution.
ValidationMode ExcelSheetNameValidationMode optionalposition: namedpipeline: Falsevalues: 2
Controls how invalid sheet names are handled.
Possible values: Sanitize, Strict

Outputs

OfficeIMO.Excel.ExcelSheet