Condividi tramite


ListObject.Sort Proprietà

Definizione

Ottiene le colonne di ordinamento e la sequenza di ordinamento per la raccolta ListObject.

public:
 property Microsoft::Office::Interop::Excel::Sort ^ Sort { Microsoft::Office::Interop::Excel::Sort ^ get(); };
public Microsoft.Office.Interop.Excel.Sort Sort { get; }
member this.Sort : Microsoft.Office.Interop.Excel.Sort
Public ReadOnly Property Sort As Sort

Valore della proprietà

Oggetto Microsoft.Office.Interop.Excel.Sort che rappresenta la colonna o le colonne di ordinamento e l'ordinamento per la ListObject raccolta.

Esempio

Nell'esempio di codice seguente viene aggiunto un ListObject oggetto al foglio di lavoro corrente. L'esempio popola quindi , ListObjectche corrisponde a una tabella di Excel, con due righe di dati arbitrari e specifica che l'ordinamento deve essere eseguito in ordine crescente in base all'intervallo di colonne A1:A3. Nell'esempio viene quindi chiamato il Microsoft.Office.Interop.Excel.Sort.Apply metodo per ordinare la tabella.

Questo esempio è relativo a una personalizzazione a livello di documento.

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

Si applica a