Compartilhar via


Propriedade ListObject.Sort

Obtém a coluna ou colunas de tipo, e ordem de classificação para a coleção de ListObject .

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (em Microsoft.Office.Tools.Excel.dll)

Sintaxe

'Declaração
ReadOnly Property Sort As Sort
Sort Sort { get; }

Valor de propriedade

Tipo: Microsoft.Office.Interop.Excel.Sort
Microsoft.Office.Interop.Excel.Sort que representa a coluna ou colunas de tipo, e ordem de classificação para a coleção de ListObject .

Exemplos

O exemplo de código a seguir adiciona ListObject a planilha atual. O exemplo então preenche ListObject, que corresponde a uma tabela Excel, com duas linhas de dados arbitrários e especifica que o tipo deve ser executado em ordem crescente baseado no intervalo A1 de coluna: A3. Em seguida, o exemplo chama o método de Microsoft.Office.Interop.Excel.Sort.Apply para classificar a tabela.

Este exemplo é para uma personalização de um documento nível.

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

}

Segurança do .NET Framework

Consulte também

Referência

ListObject Interface

Namespace Microsoft.Office.Tools.Excel