# Invoke-OfficeExcelAutoFit

Automatically fits Excel row heights and/or column widths.

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

**Module**

`PSWriteOffice`

**Aliases**

`ExcelAutoFit`

**Inputs**

`OfficeIMO.Excel.ExcelDocument`

**Source**

[InvokeOfficeExcelAutoFitCommand.cs:19](https://github.com/EvotecIT/PSWriteOffice/blob/main/Sources/PSWriteOffice/Cmdlets/Excel/InvokeOfficeExcelAutoFitCommand.cs#L19) 

Automatically fits Excel row heights and/or column widths.

## Syntax

```
Invoke-OfficeExcelAutoFit
[-All]
[-Column <Int32[]>]
[-Columns]
[-Row <Int32[]>]
[-Rows]
[<CommonParameters>]
```

[#](#method-invoke-officeexcelautofit-switchparameter-int32-switchparameter-int32-switchparameter)

Parameter set: `Context`

```
Invoke-OfficeExcelAutoFit
[-All]
[-Column <Int32[]>]
[-Columns]
-Document <ExcelDocument>
[-Row <Int32[]>]
[-Rows]
[-Sheet <String>]
[-SheetIndex <Int32>]
[<CommonParameters>]
```

[#](#method-invoke-officeexcelautofit-switchparameter-int32-switchparameter-exceldocument-int32-switchparameter-string-int32)

Parameter set: `Document`

## Description

Targets the current worksheet context or a worksheet on a supplied document.

## Examples

### Auto-fit columns in the current DSL sheet.

```powershell
ExcelSheet 'Data' { Invoke-OfficeExcelAutoFit -Columns }
```

Adjusts column widths for the active sheet.

## Parameters

**-All SwitchParameter optional**

Auto-fit both rows and columns.

**-Column Int32[] optional**

Auto-fit specific column indexes (1-based).

**-Columns SwitchParameter optional**

Auto-fit all columns.

**-Row Int32[] optional**

Auto-fit specific row indexes (1-based).

**-Rows SwitchParameter optional**

Auto-fit all rows.

**-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:24A9811E21902BD81175D4381ABD513F4D99FE8EDBBA8C7EAE2B437BD11E17FC -->
