ListObject.Sort, propriété

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

Espace de noms :  Microsoft.Office.Tools.Excel
Assembly :  Microsoft.Office.Tools.Excel (dans Microsoft.Office.Tools.Excel.dll)

Syntaxe

'Déclaration
ReadOnly Property Sort As Sort
Sort Sort { get; }

Valeur de propriété

Type : Microsoft.Office.Interop.Excel.Sort
Microsoft.Office.Interop.Excel.Sort qui représente la colonne ou les colonnes de tri et l'ordre de tri pour la collection ListObject.

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 sera effectué dans l'ordre croissant selon la plage de colonnes A1:A3.Ensuite, l'exemple appelle la méthode Microsoft.Office.Interop.Excel.Sort.Apply pour trier le tableau.

Cet exemple illustre une personnalisation au niveau du document.

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
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();

}

Sécurité .NET Framework

Voir aussi

Référence

ListObject Interface

Microsoft.Office.Tools.Excel, espace de noms