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:

  1. Bir çalışma sayfasında başlık satırına tıklayın. 1. 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.

  1. 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 Kıyaslama, ortalamalar ve En İyi 10 vb. gibi sayılara dayalı farklı türde filtreler
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 ile Autofilter

Aspose.Cells, Excel dosyasını temsil eden bir sınıf olan Workbook sağlar. Workbook sınıfı, Excel dosyasındaki her bir çalışma sayfasına erişim sağlayan bir WorksheetCollection içerir.

Bir çalışma sayfası Worksheet sınıfı tarafından 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, 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ın belirlenmesi için AutoFilter sınıfından bir nesnedir ve Range özelliğini sağlar. Otomatik filtre, başlık satırını oluşturan hücre aralığına uygulanır.

Her bir çalışma sayfasında, yalnızca bir filtre aralığı belirtebilirsiniz. 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şturulan AutoFilter’ı Aspose.Cells kullanarak oluşturduk.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Instantiating a Workbook object
Workbook workbook = new Workbook("AFData.xls");
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
// Creating AutoFilter by giving the cells range
AutoFilter autoFilter = worksheet.getAutoFilter();
autoFilter.setRange("A1:B1");
// Saving the modified Excel file
workbook.save("AFData_out.xls");
// Print message
System.out.println("Process completed successfully");

Farklı Türlerde Filtre

Aspose.Cells, Renk Filtresi, Tarih Filtresi, Sayı Filtresi, Metin Filtresi, Boş Filtreler ve Dolu Filtreler gibi farklı filtre türleri uygulamak için birden fazla seçenek sağlar.

Dolgu Rengi

Aspose.Cells, hücrelerin dolgu rengi özelliğine göre verileri filtrelemek için addFillColorFilter işlevini sağlar. Aşağıdaki örnekte, sayfanın ilk sütununda farklı dolgu renkleri olan bir şablon dosya, renk filtresi işlevini test etmek için kullanılır. İşlevselliği kontrol etmek için aşağıdaki dosyalar indirilebilir.

  1. ColouredCells.xlsx
  2. FilteredColouredCells.xlsx
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Instantiating a Workbook object
// Opening the Excel file through the file stream
Workbook workbook = new Workbook("ColouredCells.xlsx");
// Instantiating a CellsColor object for foreground color
CellsColor clrForeground = workbook.createCellsColor();
clrForeground.setColor(Color.getRed());
// Instantiating a CellsColor object for background color
CellsColor clrBackground = workbook.createCellsColor();
clrBackground.setColor(Color.getWhite());
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
// Call AddFillColorFilter function to apply the filter
worksheet.getAutoFilter().addFillColorFilter(0, BackgroundType.SOLID, clrForeground, clrBackground);
// Call refresh function to update the worksheet
worksheet.getAutoFilter().refresh();
// Saving the modified Excel file
workbook.save("FilteredColouredCells.xlsx");
// Print message
System.out.println("Process completed successfully");
Tarih

Filtrelenecek Ocak 2018 tarihlerine sahip tüm satırları filtrelemek gibi farklı türde tarih filtreleri uygulanabilir. Aşağıdaki örnek kod, bu filtrelemeyi addDateFilter işlevini kullanarak göstermektedir. Bu işlevselliği test etmek için aşağıdaki dosyalar kullanılabilir.

  1. Date.xlsx
  2. FilteredDate.xlsx
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Instantiating a Workbook object
// Opening the Excel file through the file stream
Workbook workbook = new Workbook("Date.xlsx");
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
// Call AddDateFilter function to apply the filter
worksheet.getAutoFilter().addDateFilter(0, DateTimeGroupingType.MONTH, 2018, 1, 0, 0, 0, 0);
// Call refresh function to update the worksheet
worksheet.getAutoFilter().refresh();
// Saving the modified Excel file
workbook.save("FilteredDate.xlsx");
// Print message
System.out.println("Process completed successfully");
Dinamik Tarih

Bazen tarihe dayalı dinamik filtreler, yıl gözetmeksizin, örneğin Ocak ayında tüm hücrelerin gerekliliği olabilir. Bu durumda, aşağıdaki örnek kodda verildiği gibi DynamicFilter işlevi kullanılır. Bu işlevselliği test etmek için aşağıdaki dosyalar kullanılabilir.

  1. Date.xlsx
  2. FilteredDynamicDate.xlsx
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Instantiating a Workbook object
// Opening the Excel file through the file stream
Workbook workbook = new Workbook("Date.xlsx");
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
// Call DynamicFilter function to apply the filter
worksheet.getAutoFilter().dynamicFilter(0, DynamicFilterType.JANUARY);
// Call refresh function to update the worksheet
worksheet.getAutoFilter().refresh();
// Saving the modified Excel file
workbook.save("FilteredDynamicDate.xlsx");
Sayı

Aspose.Cells ile sayılar arasında belirli bir aralıkta hücreleri seçerek özel filtreler uygulanabilir. Aşağıdaki örnek, sayıları filtrelemek için custom() işlevinin kullanımını göstermektedir. İşlevin işlevselliğini kontrol etmek için örnek dosyalar aşağıdaki bağlantılardan indirilebilir.

  1. Number.xlsx
  2. FilteredNumber.xlsx
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Instantiating a Workbook object
// Opening the Excel file through the file stream
Workbook workbook = new Workbook("Date.xlsx");
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
// Call DynamicFilter function to apply the filter
worksheet.getAutoFilter().dynamicFilter(0, DynamicFilterType.JANUARY);
// Call refresh function to update the worksheet
worksheet.getAutoFilter().refresh();
// Saving the modified Excel file
workbook.save("FilteredDynamicDate.xlsx");
Metin

Bir sütun metin içeriyorsa ve belirli metni içeren hücrelerin seçilmesi gerekiyorsa, aşağıdaki örnek dosyada belirli ülke adını içeren bir satır bulunan bir şablon dosya kullanılarak filter() işlevi kullanılabilir. Aşağıdaki örnek kod, aşağıdaki örnek dosyalar kullanılarak metin filtrelemesini göstermektedir.

  1. Text.xlsx
  2. FilteredText.xlsx
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Instantiating a Workbook object
// Opening the Excel file through the file stream
Workbook workbook = new Workbook("Text.xlsx");
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
// Call Filter function to apply the filter
worksheet.getAutoFilter().filter(0, "Angola");
// Call refresh function to update the worksheet
worksheet.getAutoFilter().refresh();
// Saving the modified Excel file
workbook.save("FilteredText.xlsx");
Boşluklar

Bir sütun öyle metin içeriyor ki, bazı hücreler boş ise ve yalnızca boş hücrelerin bulunduğu satırların seçilmesi gerekiyorsa, aşağıdaki örnek kodda gösterildiği gibi matchBlanks() işlevi kullanılabilir. İşlevin işlevselliğini kontrol etmek için örnek dosyalar aşağıdaki bağlantılardan indirilebilir.

  1. Boş.xlsx
  2. FiltreliBos.xlsx
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Instantiating a Workbook object
// Opening the Excel file through the file stream
Workbook workbook = new Workbook("Blank.xlsx");
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
// Call matchBlanks function to apply the filter
worksheet.getAutoFilter().matchBlanks(0);
// Call refresh function to update the worksheet
worksheet.getAutoFilter().refresh();
// Saving the modified Excel file
workbook.save("FilteredBlank.xlsx");
Boş Olmayanlar

Herhangi bir metni içeren hücrelerin filtrelenmesi gerektiğinde, aşağıdaki bağlantılardan örnek dosyalar kullanılarak MatchNonBlanks filtre işlevini kullanın.

  1. Boş.xlsx
  2. FiltreliBosOlmayan.xlsx
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Instantiating a Workbook object
// Opening the Excel file through the file stream
Workbook workbook = new Workbook("Blank.xlsx");
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
// Call matchBlanks function to apply the filter
worksheet.getAutoFilter().matchBlanks(0);
// Call refresh function to update the worksheet
worksheet.getAutoFilter().refresh();
// Saving the modified Excel file
workbook.save("FilteredBlank.xlsx");
Contains ile Özel filtre

Excel, belirli bir dize içeren satırları filtrelemek gibi özel filtreler sağlar. Bu özellik Aspose.Cells içinde kullanılabilir ve aşağıdaki örnek dosyada isimleri filtreleyerek gösterilmektedir. İşlevselliği kontrol etmek için aşağıdaki dosyalar indirilebilir.

  1. sourseOrnekUlkeIsimleri.xlsx
  2. dışörnekÜlkeAdları.xlsx
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Instantiating a Workbook object containing sample data
Workbook workbook = new Workbook("sourseSampleCountryNames.xlsx");
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
// Creating AutoFilter by giving the cells range
worksheet.getAutoFilter().setRange("A1:A18");
// Initialize filter for rows containing string "Ba"
worksheet.getAutoFilter().custom(0, FilterOperatorType.CONTAINS, "Ba");
//Refresh the filter to show/hide filtered rows
worksheet.getAutoFilter().refresh();
// Saving the modified Excel file
workbook.save("outSourseSampleCountryNames.xlsx");
Contains Kullanmadan Özel filtre

Excel, belirli bir dizeyi içermeyen satırları filtrelemek gibi özel filtreler sunar. Bu özellik Aspose.Cells’te mevcuttur ve aşağıda örnek dosyadaki isimleri filtreleyerek gösterilmiştir.

  1. sourseSampleCountryNames.xlsx.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Instantiating a Workbook object containing sample data
Workbook workbook = new Workbook("sourseSampleCountryNames.xlsx");
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
// Creating AutoFilter by giving the cells range
worksheet.getAutoFilter().setRange("A1:A18");
// Initialize filter for rows containing string "Ba"
worksheet.getAutoFilter().custom(0, FilterOperatorType.NOT_CONTAINS, "Ba");
//Refresh the filter to show/hide filtered rows
worksheet.getAutoFilter().refresh();
// Saving the modified Excel file
workbook.save("outSourseSampleCountryNames.xlsx");
Belirli bir dizeyle Başlayan Özel Filtre

Excel, belirli bir dizeyle başlayan satırları filtrelemek gibi özel filtreler sunar. Bu özellik Aspose.Cells’te mevcuttur ve aşağıda örnek dosyadaki isimleri filtreleyerek gösterilmiştir.

  1. sourseSampleCountryNames.xlsx.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Instantiating a Workbook object containing sample data
Workbook workbook = new Workbook(sourceDir + "sourseSampleCountryNames.xlsx");
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[0];
// Creating AutoFilter by giving the cells range
worksheet.AutoFilter.Range = "A1:A18";
// Initialize filter for rows starting with string "Ba"
worksheet.AutoFilter.Custom(0, FilterOperatorType.BeginsWith, "Ba");
//Refresh the filter to show/hide filtered rows
worksheet.AutoFilter.Refresh();
// Saving the modified Excel file
workbook.Save(outputDir + "outSourseSampleCountryNames.xlsx");
Belirli Bir Dize ile Biten Özel Filtre

Excel, Aspose.Cells’de mevcut olan ve aşağıdaki örnek dosyadaki isimleri filtreleyerek aşağıda gösterildiği gibi belirli bir dizeyle biten satırları filtreleyen özel filtreler sağlar.

  1. sourseSampleCountryNames.xlsx.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Instantiating a Workbook object containing sample data
Workbook workbook = new Workbook(srcDir + "sourseSampleCountryNames.xlsx");
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
// Creating AutoFilter by giving the cells range
worksheet.getAutoFilter().setRange("A1:A18");
// Initialize filter for rows starting with string "Ba"
worksheet.getAutoFilter().custom(0, FilterOperatorType.ENDS_WITH, "ia");
//Refresh the filter to show/hide filtered rows
worksheet.getAutoFilter().refresh();
// Saving the modified Excel file
workbook.save(outDir + "outSourseSampleCountryNames.xlsx");

Gelişmiş Konular