Veri Bulma veya Arama

Belirli Veri İçeren Hücreleri Bulma

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

Worksheet saati, çalışma sayfasındaki tüm hücreleri temsil eden bir koleksiyon olan Cells‘i sağlar. Cells koleksiyonu, kullanıcı tarafından belirtilen veriyi içeren hücreleri bulmak için birkaç yöntem sağlar. Bunlardan birkaçı aşağıda daha ayrıntılı olarak tartışılmıştır.

Tüm bulma yöntemleri, belirtilen arama değerini içeren hücre referanslarını döndürür.

Formül İçeren Bulma

Geliştiriciler, Cells koleksiyonunun find yöntemini çağırarak çalışma sayfasında belirtilen formülü bulabilir. find yöntemine FindOptions.setLookInType‘ı LookInType.FORMULAS olarak ayarlama ve bu parametreyi find yöntemine parametre olarak geçirme.

Genellikle find yöntemi iki veya daha fazla parametre alır:

  • Aranacak Nesne: çalışma sayfasında bulunması gereken bir nesneyi temsil eder.
  • Önceki Hücre: aynı formülle önceki hücreyi temsil eder. Bu parametre, başlangıçtan itibaren arama yapılırken null olarak ayarlanabilir.
  • Bulma Seçenekleri: Bulma kriterlerini temsil eder. Aşağıdaki örneklerde, arama yöntemlerini pratik etmek için aşağıdaki çalışma sayfası verileri kullanılır:

Örnek çalışma sayfası verileri

todo:image_alt_text

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(FindingCellsContainingFormula.class) + "data/";
// Instantiating a Workbook object
Workbook workbook = new Workbook(dataDir + "book1.xls");
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
// Finding the cell containing the specified formula
Cells cells = worksheet.getCells();
FindOptions findOptions = new FindOptions();
findOptions.setLookInType(LookInType.FORMULAS);
Cell cell = cells.find("=SUM(A5:A10)", null, findOptions);
// Printing the name of the cell found after searching worksheet
System.out.println("Name of the cell containing formula: " + cell.getName());

Stringler İçin Arama

Dize değeri içeren hücreleri aramak kolay ve esnektir. Başlangıç karakteri ile başlayan dize içeren hücreler için arama yapmak veya karakterler kümesiyle başlayan dize içeren hücreler için arama yapmak gibi farklı arama yöntemleri bulunmaktadır.

Belirli Karakterlerle Başlayan Stringler İçin Arama

Dizelerdeki ilk karakteri aramak için Cells koleksiyonunun find yöntemini çağırın, FindOptions.setLookAtType‘ı LookAtType.START_WITH olarak ayarlayın ve bu parametre olarak find yöntemine geçirin.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(FindingCellsWithStringOrNumber.class) + "data/";
// Instantiating a Workbook object
Workbook workbook = new Workbook(dataDir + "book1.xls");
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
// Finding the cell containing the specified formula
Cells cells = worksheet.getCells();
// Instantiate FindOptions
FindOptions findOptions = new FindOptions();
// Finding the cell containing a string value that starts with "Or"
findOptions.setLookAtType(LookAtType.START_WITH);
Cell cell = cells.find("SH", null, findOptions);
// Printing the name of the cell found after searching worksheet
System.out.println("Name of the cell containing String: " + cell.getName());

Belirli Karakterlerle Biten Stringler İçin Arama

Aspose.Cells ayrıca belirli karakterlerle biten dizeleri bulabilir. Dizelerin son karakterlerini aramak için Cells koleksiyonunun find yöntemini çağırın, FindOptions.setLookAtType‘ı LookAtType.END_WITH olarak ayarlayın ve bu parametre olarak find yöntemine geçirin.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(FindingCellsEndWithSpecificCharacters.class) + "data/";
// Instantiating a Workbook object
Workbook workbook = new Workbook(dataDir + "book1.xls");
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
// Finding the cell containing the specified formula
Cells cells = worksheet.getCells();
// Instantiate FindOptions
FindOptions findOptions = new FindOptions();
// Finding the cell containing a string value that ends with "es"
findOptions.setLookAtType(LookAtType.END_WITH);
Cell cell = cells.find("SH", null, findOptions);
// Printing the name of the cell found after searching worksheet
System.out.println("Name of the cell containing String: " + cell.getName());

Düzenli İfadelerle Arama: RegEx Özelliği

Düzenli bir ifade, belirli karakterlerin, kelimelerin veya desenlerin eşleştirilmesi (belirtilmesi ve tanınması) için kısa ve esnek bir yöntem sağlar.

Örneğin, abc-*xyz düzenli ifade deseni “abc-123-xyz”, “abc-985-xyz” ve “abc-pony-xyz” dizelerini eşleştirir. * joker karakterdir, bu nedenle desen, “abc” ile başlayan ve “-xyz” ile biten herhangi bir diziyi eşleştirir, ortadaki karakterlere bakılmaksızın.

Aspose.Cells, düzenli ifadelerle arama yapmanıza olanak tanır.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(FindingwithRegularExpressions.class) + "data/";
// Instantiating a Workbook object
Workbook workbook = new Workbook(dataDir + "book1.xls");
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
// Finding the cell containing the specified formula
Cells cells = worksheet.getCells();
// Instantiate FindOptions
FindOptions findOptions = new FindOptions();
// Instantiate FindOptions
FindOptions opt = new FindOptions();
// Set the search key of find() method as standard RegEx
opt.setRegexKey(true);
opt.setLookAtType(LookAtType.ENTIRE_CONTENT);
cells.find("abc[\\s]*$", null, opt);

Gelişmiş Konular