ListObject.Sort Propriété

Définition

Obtient la colonne ou les colonnes de tri et l'ordre de tri de la collection ListObject.

public Microsoft.Office.Interop.Excel.Sort Sort { get; }

Valeur de propriété

Sort

Microsoft. Office. Interop. Excel. sort qui représente la colonne ou les colonnes de tri, ainsi que l’ordre de tri de la ListObject collection.

Exemples

L’exemple de code suivant ajoute un ListObject à la feuille de calcul active. L’exemple remplit ensuite le ListObject , qui correspond à un tableau Excel, avec deux lignes de données arbitraires et spécifie que le tri doit être effectué dans l’ordre croissant en fonction de la plage de colonnes a1 : a3. Ensuite, l’exemple appelle la Microsoft.Office.Interop.Excel.Sort.Apply méthode pour trier la table.

Cet exemple est destiné à une personnalisation au niveau du document.

private void SortListObject()
{
    // Create ListObject control (table) and set table style
    Microsoft.Office.Tools.Excel.ListObject employeeTable =
        this.Controls.AddListObject(this.Range["A1"], 
        "employeeTable");

    // Populate table with some data
    Excel.Range rng;
    rng = employeeTable.InsertRowRange;
    ((Excel.Range)rng[1]).Value2 = "bb";
    ((Excel.Range)rng[2]).Value2 = "b1";
    Excel.ListRow row2 = employeeTable.ListRows.AddEx(
         true);
    rng = row2.Range;
    ((Excel.Range)rng[1]).Value2 = "aa";
    ((Excel.Range)rng[2]).Value2 = "a1";

    // Set sort properties        
    employeeTable.Sort.SortFields.Add(this.Range["A1", "A3"],
        Excel.XlSortOn.xlSortOnValues, 
        Excel.XlSortOrder.xlAscending);

    // Sort worksheet
    employeeTable.Sort.Apply();

}
Private Sub SortListObject()
    ' Create ListObject control (table) and set table style
    Dim employeeTable As Microsoft.Office.Tools.Excel.ListObject = _
        Me.Controls.AddListObject(Me.Range("A1"), "employeeTable")

    ' Populate table with some data
    Dim rng As Excel.Range
    rng = employeeTable.InsertRowRange
    rng(ColumnIndex:=1).Value2 = "bb"
    rng(ColumnIndex:=2).Value2 = "b1"
    Dim row2 As Excel.ListRow = employeeTable.ListRows.AddEx( _
        AlwaysInsert:=True)
    rng = row2.Range
    rng(ColumnIndex:=1).Value2 = "aa"
    rng(ColumnIndex:=2).Value2 = "a1"

    ' Set sort properties        
    employeeTable.Sort.SortFields.Add(Me.Range("A1", "A3"), _
        Excel.XlSortOn.xlSortOnValues, Excel.XlSortOrder.xlAscending)

    ' Sort worksheet
    employeeTable.Sort.Apply()

End Sub

S’applique à