Project

PSWriteOffice

PowerShell document automation across OfficeIMO's document, spreadsheet, presentation, PDF, Project, Access, EPUB, invoicing, and conversion engines.

Stars 654
Forks 82
Open issues 1
Total downloads 4,320,051
Release OfficeIMO-v3.5.3
Language: C# Updated: 2026-11-03
Cmdlet

Set-OfficeExcelMargins

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

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>]
#
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>]
#
Parameter set: Document

Examples

Apply a preset margin set.

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

Applies the Narrow margin preset.

Apply custom margins.

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