Bagikan melalui


ListObject.Sort Properti

Definisi

Mendapatkan kolom atau kolom pengurutan, dan urutan pengurutan ListObject untuk koleksi.

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

Nilai Properti

Microsoft.Office.Interop.Excel.Sort yang mewakili kolom atau kolom pengurutan, dan urutan pengurutan ListObject untuk kumpulan.

Contoh

Contoh kode berikut menambahkan ListObject ke lembar kerja saat ini. Contoh kemudian mengisi ListObject, yang sesuai dengan tabel Excel, dengan dua baris data arbitrer dan menentukan bahwa pengurutan akan dilakukan dalam urutan naik berdasarkan rentang kolom A1:A3. Selanjutnya, contoh memanggil Microsoft.Office.Interop.Excel.Sort.Apply metode untuk mengurutkan tabel.

Contoh ini untuk kustomisasi tingkat dokumen.

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

Berlaku untuk