# Add-OfficeExcelSheet

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

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: ExcelSheet

**Module**

`PSWriteOffice`

**Aliases**

`ExcelSheet`

**Inputs**

`OfficeIMO.Excel.ExcelDocument`

**Outputs**

`OfficeIMO.Excel.ExcelSheet`

**Source**

[AddOfficeExcelSheetCommand.cs:26](https://github.com/EvotecIT/PSWriteOffice/blob/main/Sources/PSWriteOffice/Cmdlets/Excel/AddOfficeExcelSheetCommand.cs#L26) 

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

## Syntax

```
Add-OfficeExcelSheet
[[-Content] <ScriptBlock>]
[[-Name] <String>]
[-PassThru]
[-ValidationMode <Sanitize|Strict>]
[<CommonParameters>]
```

[#](#method-add-officeexcelsheet-scriptblock-string-switchparameter-excelsheetnamevalidationmode)

Parameter set: `Context`

```
Add-OfficeExcelSheet
[[-Content] <ScriptBlock>]
-Document <ExcelDocument>
[[-Name] <String>]
[-PassThru]
[-ValidationMode <Sanitize|Strict>]
[<CommonParameters>]
```

[#](#method-add-officeexcelsheet-scriptblock-exceldocument-string-switchparameter-excelsheetnamevalidationmode)

Parameter set: `Document`

## Description

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

## Examples

### Create a sheet named Data.

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

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

Returns the worksheet so subsequent commands can target it directly.

## Parameters

**-Content ScriptBlock optionalposition: 1**

Code to execute inside the worksheet context.

**-Name String optionalposition: 0**

Name of the worksheet to create or reuse. When omitted the last sheet is reused or a default sheet is created.

**-PassThru SwitchParameter optional**

Emit the ExcelSheet object after execution.

**-ValidationMode ExcelSheetNameValidationMode optional**

Controls how invalid sheet names are handled.

Possible values: `Sanitize`, `Strict`

**-Document ExcelDocument requiredpipeline: True (ByValue)sets: Document**

Workbook that will receive the worksheet.

## 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:68D3A456A82131BB17CD51F4615E406AC08F4534819F832AACACEBAE48180611 -->
