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

ايجاد Cells يتضمن بيانات محددة

باستخدام Microsoft إكسل

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

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

باستخدام Aspose.Cells

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

إيجاد Cells الذي يحتوي على صيغة

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

  • **هدف:**الكائن المطلوب البحث عنه. يجب أن يكون النوع int ، double ، DateTime ، string ، bool.
  • **الخلية السابقة:**الخلية السابقة بنفس الكائن. يمكن ضبط هذه المعلمة على قيمة خالية في حالة البحث من البداية.
  • FindOptions: خيارات للعثور على الكائن المطلوب.

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

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Opening the Excel file
Workbook workbook = new Workbook(sourceDir + "sampleFindingCellsContainingFormula.xlsx");
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[0];
// Instantiate FindOptions Object
FindOptions findOptions = new FindOptions();
findOptions.LookInType = LookInType.Formulas;
// Finding the cell containing the specified formula
Cell cell = worksheet.Cells.Find("=SUM(A5:A10)", null, findOptions);
// Printing the name of the cell found after searching worksheet
System.Console.WriteLine("Name of the cell containing formula: " + cell.Name);

البحث عن البيانات أو الصيغ باستخدام FindOptions

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

  • قيمة البحث، البيانات أو القيمة التي سيتم البحث عنها.
  • الخلية السابقة، وهي الخلية الأخيرة التي تحتوي على نفس القيمة. يمكن ضبط هذه المعلمة على قيمة خالية عند البحث من البداية.
  • ابحث عن الخيارات، خيارات البحث.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Instantiate the workbook object
Workbook workbook = new Workbook(sourceDir + "sampleFindingDataOrFormulasUsingFindOptions.xlsx");
workbook.CalculateFormula();
// Get Cells collection
Cells cells = workbook.Worksheets[0].Cells;
// Instantiate FindOptions Object
FindOptions findOptions = new FindOptions();
// Create a Cells Area
CellArea ca = new CellArea();
ca.StartRow = 8;
ca.StartColumn = 2;
ca.EndRow = 17;
ca.EndColumn = 13;
// Set cells area for find options
findOptions.SetRange(ca);
// Set searching properties
findOptions.SearchBackward = false;
findOptions.SearchOrderByRows = true;
// Set the lookintype, you may specify, values, formulas, comments etc.
findOptions.LookInType = LookInType.Values;
// Set the lookattype, you may specify Match entire content, endswith, starwith etc.
findOptions.LookAtType = LookAtType.EntireContent;
// Find the cell with value
Cell cell = cells.Find(341, null, findOptions);
if (cell != null)
{
Console.WriteLine("Name of the cell containing the value: " + cell.Name);
}
else
{
Console.WriteLine("Record not found ");
}

إيجاد Cells يتضمن قيمة أو رقم سلسلة محدد

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

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

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Instantiate the workbook object
Workbook workbook = new Workbook(dataDir + "book1.xls");
// Get Cells collection
Cells cells = workbook.Worksheets[0].Cells;
FindOptions opts = new FindOptions();
opts.LookInType = LookInType.Values;
opts.LookAtType = LookAtType.EntireContent;
// Find the cell with the input integer or double
Cell cell1 = cells.Find(205, null, opts);
if (cell1 != null)
{
Console.WriteLine("Name of the cell containing the value: " + cell1.Name);
}
else
{
Console.WriteLine("Record not found ");
}
// Find the cell with the input string
Aspose.Cells.Cell cell2 = cells.Find("Items A", null, opts);
if (cell2 != null)
{
Console.WriteLine("Name of the cell containing the value: " + cell2.Name);
}
else
{
Console.WriteLine("Record not found ");
}
// Find the cell containing with the input string
opts.LookAtType = LookAtType.Contains;
Cell cell3 = cells.Find("Data", null, opts);
if (cell3 != null)
{
Console.WriteLine("Name of the cell containing the value: " + cell3.Name);
}
else
{
Console.WriteLine("Record not found ");
}

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