Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Invoke-OfficeExcelSort

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

Sorts the used range on the current worksheet.

Syntax

Invoke-OfficeExcelSort
[-Descending]
[-Document <ExcelDocument>]
[-Header] <String>
[-PassThru]
[-Sheet <OfficeSheetSelector>]
[<CommonParameters>]
#
Parameter set: Header
Invoke-OfficeExcelSort
[-Document <ExcelDocument>]
-Order <OrderedDictionary>
[-PassThru]
[-Sheet <OfficeSheetSelector>]
[<CommonParameters>]
#
Parameter set: Order

Examples

Sort by one column

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

Sorts the used range of the Servers sheet by the Name header.

Sort by several columns

Open-OfficeExcel -Path .\Reports\Helpdesk.xlsx {
    ExcelSheet 'Tickets' {
        ExcelSort -Order ([ordered]@{ Priority = $true; AgeDays = $false })
    }
}

Sorts tickets by priority ascending and then by age with the oldest first.

Parameters

-Descending SwitchParameter optionalsets: Header
Sort descending (single-column sort).
-Document ExcelDocument optionalpipeline: True (ByValue)
Workbook to operate on outside the DSL context.
-Header String requiredposition: 0sets: Header
Header to sort by (single-column sort).
-PassThru SwitchParameter optional
Emit the worksheet after sorting.
-Sheet OfficeSheetSelector optional
Worksheet name when using Document.
-Order OrderedDictionary requiredsets: Order
Ordered dictionary of header => ascending (true/false).

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.