Veri Bulma veya Arama
Belirli Verileri İçeren Hücreleri Bulma
Microsoft Excel Kullanımı
Microsoft Excel, kullanıcıların belirli verileri içeren bir çalışma sayfasında hücreleri bulmasına izin verir. Microsoft Excel’de Düzenle‘yi seçerseniz, arama değerini belirleyebileceğiniz bir iletişim kutusu göreceksiniz.
Burada, “Portakallar” değerini arıyoruz. Aspose.Cells, ayrıca belirli değerleri içeren hücreleri bulmayı sağlar.
Aspose.Cells Kullanımı
Aspose.Cells, bir Microsoft Excel dosyasını temsil eden Workbook sınıfını 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 sayfasındaki tüm hücreleri temsil eden bir cells koleksiyonunu sağlar. cells koleksiyonu, kullanıcı tarafından belirtilen verileri içeren bir çalışma sayfasındaki hücreleri bulmak için birkaç yöntem sağlar. Bu yöntemlerden bazıları aşağıda daha detaylı olarak tartışılmıştır.
Formül İçeren Hücreleri Bulma
Geliştiriciler, cells koleksiyonunun find yöntemini çağırarak çalışma sayfasındaki belirli bir formülü bulabilirler. Genellikle, find yöntemi üç parametre alır:
- what: Aranacak nesne. Türü int,double,DateTime,string,bool olmalıdır.
- previous_cell: Nesneyi içeren önceki hücre. Başlangıçtan itibaren arama yapılıyorsa bu parametre null olarak ayarlanabilir.
- find_options: Gerekli nesneyi bulmak için seçenekler.
Aşağıdaki örnekler, bulma yöntemlerini uygulamak için çalışma sayfası verilerini kullanır:
from aspose.cells import FindOptions, LookInType, Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Opening the Excel file | |
workbook = Workbook(sourceDir + "sampleFindingCellsContainingFormula.xlsx") | |
# Accessing the first worksheet in the Excel file | |
worksheet = workbook.worksheets[0] | |
# Instantiate FindOptions Object | |
findOptions = FindOptions() | |
findOptions.look_in_type = LookInType.FORMULAS | |
# Finding the cell containing the specified formula | |
cell = worksheet.cells.find("=SUM(A5:A10)", None, findOptions) | |
# Printing the name of the cell found after searching worksheet | |
print("Name of the cell containing formula: " + cell.name) |
FindOptions Kullanarak Veri veya Formülleri Bulma
Çeşitli FindOptions ile cells koleksiyonunun find yöntemi kullanılarak belirli değerleri bulmak mümkündür. Genellikle, find yöntemi aşağıdaki parametreleri kabul eder:
- what:, aranacak veri veya değer.
- previous_cell, aynı değeri içeren son hücre. Başlangıçtan itibaren arama yapılıyorsa bu parametre null olarak ayarlanabilir.
- find_options, bulma seçenekleri.
from aspose.cells import CellArea, FindOptions, LookAtType, LookInType, Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Instantiate the workbook object | |
workbook = Workbook(sourceDir + "sampleFindingDataOrFormulasUsingFindOptions.xlsx") | |
workbook.calculate_formula() | |
# Get Cells collection | |
cells = workbook.worksheets[0].cells | |
# Instantiate FindOptions Object | |
findOptions = FindOptions() | |
# Create a Cells Area | |
ca = CellArea() | |
ca.start_row = 8 | |
ca.start_column = 2 | |
ca.end_row = 17 | |
ca.end_column = 13 | |
# Set cells area for find options | |
findOptions.set_range(ca) | |
# Set searching properties | |
findOptions.search_backward = False | |
findOptions.seach_order_by_rows = True | |
# Set the lookintype, you may specify, values, formulas, comments etc. | |
findOptions.look_in_type = LookInType.VALUES | |
# Set the lookattype, you may specify Match entire content, endswith, starwith etc. | |
findOptions.look_at_type = LookAtType.ENTIRE_CONTENT | |
# Find the cell with value | |
cell = cells.find(341, None, findOptions) | |
if cell != None: | |
print("Name of the cell containing the value: " + cell.name) | |
else: | |
print("Record not found ") |
Belirli Dize Değeri veya Numarası İçeren Hücreleri Bulma
Belirli dize değerlerin bulunması, cells koleksiyonunda bulunan aynı find yöntemiyle çeşitli FindOptions ile çağrılabilir.
FindOptions.look_in_type ve FindOptions.look_at_type özelliklerini belirtin. Aşağıdaki örnek kod, bu özellikleri kullanarak hücrelerde dize sayısının başında, ortasında veya sonunda bulunması için nasıl kullanılacağını göstermektedir.
from aspose.cells import FindOptions, LookAtType, LookInType, 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(".") | |
# Instantiate the workbook object | |
workbook = Workbook(dataDir + "book1.xls") | |
# Get Cells collection | |
cells = workbook.worksheets[0].cells | |
opts = FindOptions() | |
opts.look_in_type = LookInType.VALUES | |
opts.look_at_type = LookAtType.ENTIRE_CONTENT | |
# Find the cell with the input integer or double | |
cell1 = cells.find(205, None, opts) | |
if cell1 != None: | |
print("Name of the cell containing the value: " + cell1.name) | |
else: | |
print("Record not found ") | |
# Find the cell with the input string | |
cell2 = cells.find("Items A", None, opts) | |
if cell2 != None: | |
print("Name of the cell containing the value: " + cell2.name) | |
else: | |
print("Record not found ") | |
# Find the cell containing with the input string | |
opts.look_at_type = LookAtType.CONTAINS | |
cell3 = cells.find("Data", None, opts) | |
if cell3 != None: | |
print("Name of the cell containing the value: " + cell3.name) | |
else: | |
print("Record not found ") |