البحث عن البيانات أو البحث
العثور على الخلايا التي تحتوي على بيانات محددة
استخدام 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.
- الخلية السابقة: الخلية السابقة بنفس الكائن. يمكن تعيين هذا المعلمة إلى قيمة null إذا كنا نبحث من البداية.
- 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
من الممكن العثور على القيم المحددة باستخدام طريقة Find من مجموعة Cells بمساعدة FindOptions مختلفة. عادةً ما تقبل الطريقة Find المعاملات التالية:
- قيمة البحث, البيانات أو القيمة التي يتم البحث عنها.
- الخلية السابقة, آخر خلية احتوت على نفس القيمة. يمكن تعيين هذه المعلمة إلى قيمة null عند البحث من البداية.
- خيارات البحث, خيارات البحث.
// 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 "); | |
} |
العثور على الخلايا التي تحتوي على قيمة سلسلة أو رقم محدد
من الممكن العثور على القيم النصية المحددة من خلال استدعاء نفس الطريقة Find الموجودة في مجموعة 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 "); | |
} |