Cmdlet
Add-OfficeExcelSheet
Adds or reuses a worksheet within the current Excel DSL scope.
Syntax
Add-OfficeExcelSheet
[[-Content] <ScriptBlock>]
[[-Name] <String>]
[-PassThru]
[-ValidationMode <Sanitize| Strict>]
[<CommonParameters>]#Parameter set:
ContextAdd-OfficeExcelSheet
[[-Content] <ScriptBlock>]
-Document <ExcelDocument>
[[-Name] <String>]
[-PassThru]
[-ValidationMode <Sanitize| Strict>]
[<CommonParameters>]#Parameter set:
DocumentDescription
Creates the sheet when missing, pushes it onto the DSL stack, and executes the nested script block.
Examples
Create a sheet named Data.
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.
$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
- Code to execute inside the worksheet context.
- -Name String
- Name of the worksheet to create or reuse. When omitted the last sheet is reused or a default sheet is created.
- -PassThru SwitchParameter
- Emit the ExcelSheet object after execution.
- -ValidationMode ExcelSheetNameValidationMode
- Controls how invalid sheet names are handled.
- Possible values:
Sanitize,Strict - -Document ExcelDocument
- 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.