البحث عن البيانات أو البحث

العثور على الخلايا التي تحتوي على بيانات محددة

استخدام Microsoft Excel

يسمح Microsoft Excel للمستخدمين بالعثور على الخلايا في ورقة العمل التي تحتوي على بيانات محددة. إذا قمت باختيار تحرير من قائمة العثور في Microsoft Excel، سترى مربع حوار حيث يمكنك تحديد قيمة البحث.

هنا، نبحث عن القيمة “البرتقال”. تسمح Aspose.Cells أيضًا للمطورين بالعثور على الخلايا في ورقة العمل التي تحتوي على القيم المحددة.

استخدام Aspose.Cells

توفر Aspose.Cells فئةً تمثل ملف Microsoft Excel. تحتوي الفئة Workbook على مجموعة worksheets التي تسمح بالوصول إلى كل ورقة عمل في ملف Excel. يتم تمثيل ورقة العمل بواسطة الفئة Worksheet. توفر الفئة Worksheet مجموعة cells التي تمثل جميع الخلايا في ورقة العمل. توفر مجموعة cells عدة طرق للعثور على الخلايا في ورقة العمل التي تحتوي على بيانات محددة من قبل المستخدم. يتم مناقشة بعض هذه الطرق أدناه بمزيد من التفصيل.

العثور على الخلايا التي تحتوي على صيغة

يمكن للمطورين العثور على صيغة محددة في ورقة العمل عن طريق استدعاء الطريقة find من كجموعة cells. عادةً ما تقبل الطريقة find ثلاثة معاملات:

  • ما هي: الكائن الذي يجب البحث عنه. يجب أن يكون النوع int,double,DateTime,string,bool.
  • previous_cell: الخلية السابقة التي تحتوي على نفس الكائن. يمكن تعيين هذا المعلمة على قيمة null إذا كان البحث من البداية.
  • find_options: خيارات للعثور على الكائن المطلوب.

تستخدم الأمثلة أدناه بيانات ورقة العمل لممارسة طرق البحث:

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

من الممكن العثور على القيم المحددة باستخدام طريقة find من مجموعة cells بمساعدة FindOptions مختلفة. عادةً ما تقبل الطريقة find المعاملات التالية:

  • ما هي:، البيانات أو القيمة التي يتعين البحث عنها.
  • الخلية_السابقة, الخلية الأخيرة التي احتوت على نفس القيمة. يمكن تعيين هذا المعلمة إلى قيمة null عند البحث من البداية.
  • find_options, find options.
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 ")

العثور على الخلايا التي تحتوي على قيمة سلسلة أو رقم محدد

من الممكن العثور على القيم النصية المحددة من خلال استدعاء نفس الطريقة find الموجودة في مجموعة cells بمختلف FindOptions.

حدد الخصائص FindOptions.look_in_type و FindOptions.look_at_type. يوضح الكود المثال التالي كيفية استخدام هذه الخصائص للعثور على الخلايا بعدد متنوع من السلاسل حسب البداية أو الوسط أو النهاية من سلسلة الخلية.

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 ")

مواضيع متقدمة