Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Invoke-OfficeExcelAutoFit

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

Fits column widths and row heights to their content.

Syntax

Invoke-OfficeExcelAutoFit
[-Column <Object[]>]
[-Document <ExcelDocument>]
[-Row <Object[]>]
[-Sheet <OfficeSheetSelector>]
[<CommonParameters>]
#
Parameter set: Default

Examples

Fit every column and row

Open-OfficeExcel -Path .\Reports\Inventory.xlsx {
    ExcelSheet 'Servers' {
        ExcelAutoFit
    }
}

Fits all columns and rows of the current sheet to their content.

Fit only the columns you changed

Open-OfficeExcel -Path .\Reports\Changes.xlsx {
    ExcelSheet 'Changes' {
        ExcelColumn F -Values (Import-OfficeCsv -Path .\Data\Change-Notes.csv).Note -StartRow 2
        ExcelAutoFit -Column E, F
    }
}

Writes long notes into column F and refits only columns E and F, leaving the widths of the rest as designed.

Parameters

-Column Object[] optional
Auto-fit specific column indexes (1-based).
-Document ExcelDocument optionalpipeline: True (ByValue)
Caller-owned workbook; omission uses the enclosing Excel content block.
-Row Object[] optional
Auto-fit specific row indexes (1-based).
-Sheet OfficeSheetSelector optional
Worksheet name, one-based position or native worksheet object. Multi-sheet commands also accept wildcard names.

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.