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

Set-OfficeExcelMargins

Aliases: ExcelMargins
Namespace PSWriteOffice
Aliases
ExcelMargins
Inputs
OfficeIMO.Excel.ExcelDocument

Sets page margins on a worksheet.

Remarks

Sets page margins on a worksheet.

Examples

Authored help example

Apply a preset margin set.

PS>


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

Applies the Narrow margin preset.

Apply custom margins.

PS>


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

Sets custom margins in inches.

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

Set-OfficeExcelMargins [-Bottom <Double>] [-Footer <Double>] [-Header <Double>] [-Left <Double>] [-PassThru] [-Preset <Normal|Narrow|Moderate|Wide>] [-Right <Double>] [-Top <Double>] [<CommonParameters>]
#
Parameter set: Context

Parameters

Bottom Double optionalposition: namedpipeline: False
Bottom margin in inches.
Footer Double optionalposition: namedpipeline: False
Footer margin in inches.
Header Double optionalposition: namedpipeline: False
Header margin in inches.
Left Double optionalposition: namedpipeline: False
Left margin in inches.
PassThru SwitchParameter optionalposition: namedpipeline: False
Emit the worksheet after applying margins.
Preset ExcelMarginPreset optionalposition: namedpipeline: Falsevalues: 4
Margin preset to apply.
Possible values: Normal, Narrow, Moderate, Wide
Right Double optionalposition: namedpipeline: False
Right margin in inches.
Top Double optionalposition: namedpipeline: False
Top margin in inches.
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>]
#
Parameter set: Document

Parameters

Bottom Double optionalposition: namedpipeline: False
Bottom margin in inches.
Document ExcelDocument requiredposition: namedpipeline: True (ByValue)
Workbook to operate on outside the DSL context.
Footer Double optionalposition: namedpipeline: False
Footer margin in inches.
Header Double optionalposition: namedpipeline: False
Header margin in inches.
Left Double optionalposition: namedpipeline: False
Left margin in inches.
PassThru SwitchParameter optionalposition: namedpipeline: False
Emit the worksheet after applying margins.
Preset ExcelMarginPreset optionalposition: namedpipeline: Falsevalues: 4
Margin preset to apply.
Possible values: Normal, Narrow, Moderate, Wide
Right Double optionalposition: namedpipeline: False
Right margin in inches.
Sheet String optionalposition: namedpipeline: False
Worksheet name when using Document.
SheetIndex Int32 optionalposition: namedpipeline: False
Worksheet index (0-based) when using Document.
Top Double optionalposition: namedpipeline: False
Top margin in inches.