# Set-OfficeExcelMargins

Sets page margins on a worksheet. Review available syntax, parameters, pipeline guidance, and reference details in PSWriteOffice API Reference.

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 **727**

Forks **84**

Open issues **7**

Total downloads **5,275,783**

Release **OfficeIMO-v3.6.2**

Language: C# Updated: 2026-11-24

Cmdlet 

Aliases: ExcelMargins

**Module**

`PSWriteOffice`

**Aliases**

`ExcelMargins`

**Inputs**

`OfficeIMO.Excel.ExcelDocument`

**Source**

[SetOfficeExcelMarginsCommand.cs:22](https://github.com/EvotecIT/PSWriteOffice/blob/main/Sources/PSWriteOffice/Cmdlets/Excel/SetOfficeExcelMarginsCommand.cs#L22) 

Sets page margins on a worksheet.

## Syntax

```
Set-OfficeExcelMargins
[-Bottom <Double>]
[-Footer <Double>]
[-Header <Double>]
[-Left <Double>]
[-PassThru]
[-Preset <Normal|Narrow|Moderate|Wide>]
[-Right <Double>]
[-Top <Double>]
[<CommonParameters>]
```

[#](#method-set-officeexcelmargins-double-double-double-double-switchparameter-excelmarginpreset-double-double)

Parameter set: `Context`

```
Set-OfficeExcelMargins
[-Bottom <Double>]
-Document <ExcelDocument>
[-Footer <Double>]
[-Header <Double>]
[-Left <Double>]
[-PassThru]
[-Preset <Normal|Narrow|Moderate|Wide>]
[-Right <Double>]
[-Sheet <String>]
[-SheetIndex <Int32>]
[-Top <Double>]
[<CommonParameters>]
```

[#](#method-set-officeexcelmargins-double-exceldocument-double-double-double-switchparameter-excelmarginpreset-double-string-int32-double)

Parameter set: `Document`

## Examples

### Apply a preset margin set.

```powershell
ExcelSheet 'Data' { Set-OfficeExcelMargins -Preset Narrow }
```

Applies the Narrow margin preset.

### Apply custom margins.

```powershell
ExcelSheet 'Data' { Set-OfficeExcelMargins -Left 0.5 -Right 0.5 -Top 0.75 -Bottom 0.75 }
```

Sets custom margins in inches.

## Parameters

**-Bottom Double optional**

Bottom margin in inches.

**-Footer Double optional**

Footer margin in inches.

**-Header Double optional**

Header margin in inches.

**-Left Double optional**

Left margin in inches.

**-PassThru SwitchParameter optional**

Emit the worksheet after applying margins.

**-Preset ExcelMarginPreset optional**

Margin preset to apply.

Possible values: `Normal`, `Narrow`, `Moderate`, `Wide`

**-Right Double optional**

Right margin in inches.

**-Top Double optional**

Top margin in inches.

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

Workbook to operate on outside the DSL context.

**-Sheet String optionalsets: Document**

Worksheet name when using Document.

**-SheetIndex Int32 optionalsets: Document**

Worksheet index (0-based) when using Document.

## 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:586E88D37E8E9DC7C96BADCC2BEDDF8A84ADA03B29A76C94824F8D1954768200 -->
