Veri Filtreleme
Veriye Otomatik Filtreleme Uygulama
Otomatik filtreleme, listede görüntülemek istediğiniz yalnızca öğeleri seçmenin en hızlı yoludur. Otomatik filtreleme özelliği, kullanıcılara belirli bir kriterlere göre listedeki öğeleri filtreleme olanağı sağlar. Metne, sayılara veya tarih bilgilerine göre filtreleme yapın.
Microsoft Excel’de Otomatik Filtreleme
Microsoft Excel’de otomatik filtreleme özelliğini etkinleştirmek için:
- Bir çalışma sayfasında başlık satırına tıklayın.
- Veri menüsünden Filtre seçin ve ardından Otomatik Filtre‘yi seçin.
Bir çalışma sayfasına otomatik filtre uyguladığınızda, filtre anahtarları (siyah oklar) sütun başlıklarının sağında görünür.
- Bir filtre okuna tıklayarak filtre seçeneklerinin listesini görüntüleyin.
Otomatik filtre seçeneklerinden bazıları:
Seçenekler | Açıklama |
---|---|
All | Listedeki tüm öğeleri bir kez gösterir. |
Custom | İçerir/içermez gibi özel filtre kriterleri |
Filter by Color | Dolgu rengine göre filtreleme |
Date Filters | Tarihe göre farklı kriterlere dayalı filtreleme |
Number Filters | Karşılaştırma, ortalama ve En Üst 10 vb. gibi sayılar üzerinde farklı filtre türleri. |
Text Filters | Başlangıç, son, içerir vb. gibi farklı filtreler |
Blanks/Non Blanks | Bu filtreler Metin Filtre Boş üzerinden uygulanabilir |
Kullanıcılar, Microsoft Excel’de bu seçenekleri kullanarak çalışma sayfalarındaki verileri manuel olarak filtreler.
Aspose.Cells for Python Excel Kütüphanesi ile Otomatik Filtrele
Aspose.Cells for Python via .NET, bir Excel dosyasını temsil eden Workbook adında bir sınıf sağlar. Workbook sınıfı, Excel dosyasındaki her çalışma sayfasına erişim sağlayan Worksheets koleksiyonunu içerir.
Bir çalışma sayfası Worksheet sınıfı ile temsil edilir. Worksheet sınıfı, çalışma sayfalarını yönetmek için geniş bir özellik ve yöntem yelpazesi sağlar. Bir otomatik filtre oluşturmak için AutoFilter sınıfının Worksheet sınıfının AutoFilter özelliğini kullanın. AutoFilter özelliği, başlık satırını oluşturan hücre aralığını belirtmek için Range özelliğini sağlar. Bir otomatik filtre, başlık satırını oluşturan hücre aralığına uygulanır.
Her çalışma sayfasında yalnızca bir filtre aralığı belirleyebilirsiniz. Bu, Microsoft Excel tarafından sınırlıdır. Özel veri filtrelemesi için AutoFilter.Custom yöntemini kullanın.
Aşağıdaki örnekte, yukarıdaki bölümde Microsoft Excel kullanarak oluşturduğumuz gibi Aspose.Cells for Python via .NET kullanarak aynı Otomatik Filtreyi oluşturduk.
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Instantiating a Workbook object | |
# Opening the Excel file through the file stream | |
workbook = Workbook(dataDir + "book1.xls") | |
# Accessing the first worksheet in the Excel file | |
worksheet = workbook.worksheets[0] | |
# Creating AutoFilter by giving the cells range of the heading row | |
worksheet.auto_filter.range = "A1:B1" | |
# Saving the modified Excel file | |
workbook.save(dataDir + "output.out.xls") |
Farklı Türlerde Filtre
Aspose.Cells for Python via .NET, Renk Filtresi, Tarih Filtresi, Sayı Filtresi, Metin Filtresi, Boş Filtreler ve Boş Olmayan Filtreler gibi farklı filtre türleri uygulamak için birden fazla seçenek sunar.
Dolgu Rengi
Aspose.Cells for Python via .NET, hücrelerin dolgu rengi özelliğine göre verileri filtrelemek için AddFillColorFilter işlevini sağlar. Aşağıdaki örnekte, sayfaın ilk sütununda farklı dolgu renklerine sahip bir şablon dosyası, renk filtreleme işlevini test etmek için kullanılır. Örnek dosyalar aşağıdaki bağlantılardan indirilebilir.
from aspose.cells import BackgroundType, Workbook | |
from aspose.pydrawing import Color | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
# Source directory | |
sourceDir = RunExamples.Get_SourceDirectory() | |
# Output directory | |
outputDir = RunExamples.Get_OutputDirectory() | |
# Instantiating a Workbook object | |
# Opening the Excel file through the file stream | |
workbook = Workbook(sourceDir + "ColouredCells.xlsx") | |
# Instantiating a CellsColor object for foreground color | |
clrForeground = workbook.create_cells_color() | |
clrForeground.color = Color.red | |
# Instantiating a CellsColor object for background color | |
clrBackground = workbook.create_cells_color() | |
clrBackground.color = Color.white | |
# Accessing the first worksheet in the Excel file | |
worksheet = workbook.worksheets[0] | |
# Call AddFillColorFilter function to apply the filter | |
worksheet.auto_filter.add_fill_color_filter(0, BackgroundType.SOLID, clrForeground, clrBackground) | |
# Call refresh function to update the worksheet | |
worksheet.auto_filter.refresh() | |
# Saving the modified Excel file | |
workbook.save(outputDir + "FilteredColouredCells.xlsx") |
Tarih
Ocak 2018 tarihine sahip tüm satırları filtrelemek gibi farklı tarih filtreleri uygulanabilir. Aşağıdaki örnek kod, AddDateFilter işlevini kullanarak bu filtrelemeyi göstermektedir. Örnek dosyalar aşağıda verilmiştir.
from aspose.cells import DateTimeGroupingType, Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
# Source directory | |
sourceDir = RunExamples.Get_SourceDirectory() | |
# Output directory | |
outputDir = RunExamples.Get_OutputDirectory() | |
# Instantiating a Workbook object | |
# Opening the Excel file through the file stream | |
workbook = Workbook(sourceDir + "Date.xlsx") | |
# Accessing the first worksheet in the Excel file | |
worksheet = workbook.worksheets[0] | |
# Call AddDateFilter function to apply the filter | |
worksheet.auto_filter.add_date_filter(0, DateTimeGroupingType.MONTH, 2018, 1, 0, 0, 0, 0) | |
# Call refresh function to update the worksheet | |
worksheet.auto_filter.refresh() | |
# Saving the modified Excel file | |
workbook.save(outputDir + "FilteredDate.xlsx") |
Dinamik Tarih
Zaman zaman yıla bağlı olmaksızın, örneğin Ocak ayında tüm hücrelerin tarih temelli dinamik filtrelemelere ihtiyaç duyulabilir. Bu durumda DynamicFilter işlevi aşağıdaki örnek kodda olduğu gibi kullanılır. Örnek dosyalar aşağıdaki verilmiştir.
from aspose.cells import DynamicFilterType, Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
# Source directory | |
sourceDir = RunExamples.Get_SourceDirectory() | |
# Output directory | |
outputDir = RunExamples.Get_OutputDirectory() | |
# Instantiating a Workbook object | |
# Opening the Excel file through the file stream | |
workbook = Workbook(sourceDir + "Date.xlsx") | |
# Accessing the first worksheet in the Excel file | |
worksheet = workbook.worksheets[0] | |
# Call DynamicFilter function to apply the filter | |
worksheet.auto_filter.dynamic_filter(0, DynamicFilterType.JANUARY) | |
# Call refresh function to update the worksheet | |
worksheet.auto_filter.refresh() | |
# Saving the modified Excel file | |
workbook.save(outputDir + "FilteredDynamicDate.xlsx") |
Sayı
Aspose.Cells for Python via .NET ile bir Custom() işlevi kullanarak özel filtreler uygulanabilir. Aşağıdaki örnek, sayıları filtrelemek için Custom() işlevinin kullanımını göstermektedir. Örnek dosyalar aşağıda verilmiştir.
from aspose.cells import FilterOperatorType, Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
# Source directory | |
sourceDir = RunExamples.Get_SourceDirectory() | |
# Output directory | |
outputDir = RunExamples.Get_OutputDirectory() | |
# Instantiating a Workbook object | |
# Opening the Excel file through the file stream | |
workbook = Workbook(sourceDir + "Number.xlsx") | |
# Accessing the first worksheet in the Excel file | |
worksheet = workbook.worksheets[0] | |
# Call Custom function to apply the filter | |
worksheet.auto_filter.custom(0, FilterOperatorType.GREATER_OR_EQUAL, 5, True, FilterOperatorType.LESS_OR_EQUAL, 10) | |
# Call refresh function to update the worksheet | |
worksheet.auto_filter.refresh() | |
# Saving the modified Excel file | |
workbook.save(outputDir + "FilteredNumber.xlsx") |
Metin
Eğer bir sütun metin içeriyorsa ve belirli metni içeren hücreler seçilmek isteniyorsa, Filter() işlevi kullanılabilir. Aşağıdaki örnekte, şablon dosyası ülkelerin listesini içerir ve belirli bir ülke adını içeren satır seçilmelidir. Aşağıdaki kod, metni filtrelemeyi göstermektedir. Örnek dosyalar aşağıda verilmiştir.
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
# Source directory | |
sourceDir = RunExamples.Get_SourceDirectory() | |
# Output directory | |
outputDir = RunExamples.Get_OutputDirectory() | |
# Instantiating a Workbook object | |
# Opening the Excel file through the file stream | |
workbook = Workbook(sourceDir + "Text.xlsx") | |
# Accessing the first worksheet in the Excel file | |
worksheet = workbook.worksheets[0] | |
# Call Filter function to apply the filter | |
worksheet.auto_filter.filter(0, "Angola") | |
# Call refresh function to update the worksheet | |
worksheet.auto_filter.refresh() | |
# Saving the modified Excel file | |
workbook.save(outputDir + "FilteredText.xlsx") |
Boşluklar
Eğer bir sütun metin içeriyorsa ve bazı hücreler boşsa ve yalnızca boş hücrelerin bulunduğu satırları seçmek gerekiyorsa, MatchBlanks() işlevi aşağıda gösterildiği gibi kullanılabilir. Örnek dosyalar aşağıda verilmiştir.
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
# Source directory | |
sourceDir = RunExamples.Get_SourceDirectory() | |
# Output directory | |
outputDir = RunExamples.Get_OutputDirectory() | |
# Instantiating a Workbook object | |
# Opening the Excel file through the file stream | |
workbook = Workbook(sourceDir + "Blank.xlsx") | |
# Accessing the first worksheet in the Excel file | |
worksheet = workbook.worksheets[0] | |
# Call MatchBlanks function to apply the filter | |
worksheet.auto_filter.match_blanks(0) | |
# Call refresh function to update the worksheet | |
worksheet.auto_filter.refresh() | |
# Saving the modified Excel file | |
workbook.save(outputDir + "FilteredBlank.xlsx") |
Boş Olmayanlar
Herhangi bir metin içeren hücrelerin filtrelenmesi gerektiğinde, aşağıda gösterildiği gibi MatchNonBlanks filtre işlevi kullanılır. Örnek dosyalar aşağıda verilmiştir.
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
# Source directory | |
sourceDir = RunExamples.Get_SourceDirectory() | |
# Output directory | |
outputDir = RunExamples.Get_OutputDirectory() | |
# Instantiating a Workbook object | |
# Opening the Excel file through the file stream | |
workbook = Workbook(sourceDir + "Blank.xlsx") | |
# Accessing the first worksheet in the Excel file | |
worksheet = workbook.worksheets[0] | |
# Call MatchNonBlanks function to apply the filter | |
worksheet.auto_filter.match_non_blanks(0) | |
# Call refresh function to update the worksheet | |
worksheet.auto_filter.refresh() | |
# Saving the modified Excel file | |
workbook.save(outputDir + "FilteredNonBlank.xlsx") |
Contains ile Özel filtre
Excel, belirli bir dize içeren satırları filtrelemek gibi özel filtreler sağlar. Bu özellik, Aspose.Cells for Python via .NET’de mevcuttur ve örnek dosyadaki isimleri filtreleyerek aşağıda gösterilmiştir. Örnek dosyalar aşağıda verilmiştir.
from aspose.cells import FilterOperatorType, Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Instantiating a Workbook object containing sample data | |
workbook = Workbook("sourseSampleCountryNames.xlsx") | |
# Accessing the first worksheet in the Excel file | |
worksheet = workbook.worksheets[0] | |
# Creating AutoFilter by giving the cells range | |
worksheet.auto_filter.range = "A1:A18" | |
# Initialize filter for rows containing string "Ba" | |
worksheet.auto_filter.custom(0, FilterOperatorType.CONTAINS, "Ba") | |
# Refresh the filter to show/hide filtered rows | |
worksheet.auto_filter.refresh() | |
# Saving the modified Excel file | |
workbook.save("outSourseSampleCountryNames.xlsx") |
Contains Kullanmadan Özel filtre
Excel, belirli bir dize içermeyen satırları filtrelemek gibi özel filtreler sağlar. Bu özellik, Aspose.Cells for Python via .NET’de mevcuttur ve örnek dosyadaki isimleri filtreleyerek aşağıda gösterilmiştir.
from aspose.cells import FilterOperatorType, Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Instantiating a Workbook object containing sample data | |
workbook = Workbook("sourseSampleCountryNames.xlsx") | |
# Accessing the first worksheet in the Excel file | |
worksheet = workbook.worksheets[0] | |
# Creating AutoFilter by giving the cells range | |
worksheet.auto_filter.range = "A1:A18" | |
# Initialize filter for rows containing string "Ba" | |
worksheet.auto_filter.custom(0, FilterOperatorType.NOT_CONTAINS, "Be") | |
# Refresh the filter to show/hide filtered rows | |
worksheet.auto_filter.refresh() | |
# Saving the modified Excel file | |
workbook.save("outSourseSampleCountryNames.xlsx") |
Belirli bir dizeyle Başlayan Özel Filtre
Excel, belirli bir dize ile başlayan satırları filtrelemek gibi özel filtreler sağlar. Bu özellik, Aspose.Cells for Python via .NET’de mevcuttur ve örnek dosyadaki isimleri filtreleyerek aşağıda gösterilmiştir.
from aspose.cells import FilterOperatorType, Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Instantiating a Workbook object containing sample data | |
workbook = Workbook(sourceDir + "sourseSampleCountryNames.xlsx") | |
# Accessing the first worksheet in the Excel file | |
worksheet = workbook.worksheets[0] | |
# Creating AutoFilter by giving the cells range | |
worksheet.auto_filter.range = "A1:A18" | |
# Initialize filter for rows starting with string "Ba" | |
worksheet.auto_filter.custom(0, FilterOperatorType.BEGINS_WITH, "Ba") | |
# Refresh the filter to show/hide filtered rows | |
worksheet.auto_filter.refresh() | |
# Saving the modified Excel file | |
workbook.save(outputDir + "outSourseSampleCountryNames.xlsx") |
Belirli Bir Dize ile Biten Özel Filtre
Excel, belirli bir dize ile biten satırları filtrelemek gibi özel filtreler sağlar. Bu özellik, Aspose.Cells for Python via .NET’de mevcuttur ve örnek dosyadaki isimleri filtreleyerek aşağıda gösterilmiştir.
from aspose.cells import FilterOperatorType, Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Instantiating a Workbook object containing sample data | |
workbook = Workbook(sourceDir + "sourseSampleCountryNames.xlsx") | |
# Accessing the first worksheet in the Excel file | |
worksheet = workbook.worksheets[0] | |
# Creating AutoFilter by giving the cells range | |
worksheet.auto_filter.range = "A1:A18" | |
# Initialize filter for rows end with string "ia" | |
worksheet.auto_filter.custom(0, FilterOperatorType.BEGINS_WITH, "ia") | |
# Refresh the filter to show/hide filtered rows | |
worksheet.auto_filter.refresh() | |
# Saving the modified Excel file | |
workbook.save(outputDir + "outSourseSampleCountryNames.xlsx") |