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

ايجاد Cells الذي يحتوي على بيانات محددة

Aspose.Cells يوفر فصل دراسي ،دفتر العمل ، يمثل ملف Excel. الدفتر العمل فئة تحتوي علىورقة العمل ، مجموعة تسمح بالوصول إلى كل ورقة عمل في ملف Excel. يتم تمثيل ورقة العمل بواسطةورقة عملصف دراسي.

الورقة عمل فئة تقدمCells ، مجموعة تمثل جميع الخلايا في ورقة العملCellsتوفر المجموعة عدة طرق للبحث عن الخلايا في ورقة عمل تحتوي على بيانات محددة من قبل المستخدم. تتم مناقشة عدد قليل من هذه الأساليب أدناه بمزيد من التفصيل.

تُرجع جميع طرق البحث مراجع الخلايا لأي خلايا تحتوي على قيمة البحث المحددة.

البحث عن صيغة

يمكن للمطورين العثور على صيغة محددة في ورقة العمل عن طريق استدعاءCells المجموعةتجد طريقة تحديدFindOptions.setLookInType إلىLookInType.FormULASوتمريره كمعامل إلىتجد طريقة.

عادةً ما يكون ملفتجد يقبل الأسلوب معلمتين أو أكثر:

  • كائن للبحث: يمثل كائنًا مطلوبًا للبحث عنه في ورقة العمل.
  • Cell السابق: يمثل الخلية السابقة بنفس الصيغة. يمكن ضبط هذه المعلمة على قيمة خالية عند البحث من البداية.
  • خيارات البحث: تمثل معايير البحث. في الأمثلة أدناه ، تُستخدم بيانات ورقة العمل التالية لممارسة طرق البحث:

نموذج بيانات ورقة العمل

ما يجب القيام به: image_بديل_نص

// 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());

البحث عن سلاسل

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

البحث عن سلاسل تبدأ بأحرف معينة

للبحث عن الحرف الأول في السلسلة ، قم باستدعاءCells المجموعةتجد الطريقة ، اضبط ملفFindOptions.setLookAtType إلىLookAtType.START_WITHوتمريره كمعامل إلىتجد طريقة.

// 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());

البحث عن سلاسل تنتهي بأحرف معينة

يمكن أن يقوم Aspose.Cells أيضًا بإيجاد سلاسل تنتهي بحروف معينة. للبحث عن الأحرف الأخيرة في السلسلة ، قم باستدعاءCells المجموعةتجد الطريقة ، اضبط ملفFindOptions.setLookAtType إلىLookAtType.END_WITHوتمريره كمعامل إلىتجد طريقة.

// 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());

البحث باستخدام التعبيرات العادية: ميزة RegEx

يوفر التعبير العادي وسيلة موجزة ومرنة لمطابقة (تحديد والتعرف على) سلاسل النص ، مثل أحرف أو كلمات أو أنماط معينة.

على سبيل المثال ، نمط التعبير العادي abc-* ~~ xyz ~~ تطابق السلاسل “abc-123-xyz” و “abc-985-xyz” و “abc-pony-xyz”.* هي حرف بدل لذا فإن النمط يطابق أي سلاسل تبدأ بـ “abc” وتنتهي بـ “-xyz” ، بغض النظر عن الأحرف الموجودة في المنتصف.

يسمح لك Aspose.Cells بالبحث باستخدام التعابير النمطية.

// 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);

موضوعات مسبقة