Cmdlet
Invoke-OfficeExcelAutoFit
Fits column widths and row heights to their content.
Syntax
Invoke-OfficeExcelAutoFit
[-Column <Object[]>]
[-Document <ExcelDocument>]
[-Row <Object[]>]
[-Sheet <OfficeSheetSelector>]
[<CommonParameters>]#Parameter set:
DefaultExamples
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[]
- Auto-fit specific column indexes (1-based).
- -Document ExcelDocument
- Caller-owned workbook; omission uses the enclosing Excel content block.
- -Row Object[]
- Auto-fit specific row indexes (1-based).
- -Sheet OfficeSheetSelector
- 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.