البحث عن البيانات أو البحث
العثور على الخلايا التي تحتوي على بيانات محددة
استخدام Microsoft Excel
يسمح Microsoft Excel للمستخدمين بالعثور على خلايا في ورقة العمل تحتوي على بيانات محددة. إذا قمت باختيار تحرير من قائمة بحث في Microsoft Excel، سترى مربع حوار يمكنك تحديد قيمة البحث فيها.
هنا، نبحث عن القيمة “البرتقال”. تسمح Aspose.Cells أيضًا للمطورين بالعثور على الخلايا في ورقة العمل التي تحتوي على القيم المحددة.
** باستخدام Aspose.Cells for Node.js via C++**
توفر Aspose.Cells فئة، Workbook، التي تمثل ملف Microsoft Excel. تحتوي فئة Workbook على مجموعة Workbook.getWorksheets() التي تتيح الوصول إلى كل ورقة عمل في ملف Excel. تمثل ورقة العمل بواسطة فئة Worksheet. توفر فئة Worksheet مجموعة getCells() تمثل جميع الخلايا في ورقة العمل. توفر مجموعة Cells العديد من الطرق للعثور على خلايا تحتوي على بيانات تم تحديدها من قبل المستخدم، ومن بين هذه الطرق نوقش بشكل أكثر تفصيلًا أدناه.
العثور على الخلايا التي تحتوي على صيغة
يمكن للمطورين العثور على صيغة محددة في ورقة العمل من خلال استدعاء مجموعة Cells وطريقة find الخاصة بها. عادةً، تقبل طريقة find ثلاثة معلمات:
- الكائن: الكائن الذي تبحث عنه. يجب أن يكون النوع int أو double أو DateTime أو string أو bool.
- الخلية السابقة: الخلية السابقة بنفس الكائن. يمكن تعيين هذا المعامل إلى null إذا كنت تبحث من البداية.
- FindOptions: خيارات للبحث عن الكائن المطلوب.
تستخدم الأمثلة أدناه بيانات ورقة العمل لممارسة طرق البحث:
const AsposeCells = require("aspose.cells.node"); | |
const path = require("path"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
// Opening the Excel file | |
const workbook = new AsposeCells.Workbook(path.join(dataDir, "sampleFindingCellsContainingFormula.xlsx")); | |
// Accessing the first worksheet in the Excel file | |
const worksheet = workbook.getWorksheets().get(0); | |
// Instantiate FindOptions Object | |
const findOptions = new AsposeCells.FindOptions(); | |
findOptions.setLookInType(AsposeCells.LookInType.Formulas); | |
// Finding the cell containing the specified formula | |
const cell = worksheet.getCells().find("=SUM(A5:A10)", null, findOptions); | |
// Printing the name of the cell found after searching worksheet | |
console.log("Name of the cell containing formula: " + cell.getName()); |
العثور على البيانات أو الصيغ باستخدام FindOptions
من الممكن العثور على القيم المحددة باستخدام طريقة Cells.find(object, Cell) من مجموعة Cells مع عدة FindOptions. عادةً، تقبل طريقة find المعلمات التالية:
- قيمة البحث, البيانات أو القيمة التي يتم البحث عنها.
- الخلية السابقة, آخر خلية احتوت على نفس القيمة. يمكن تعيين هذه المعلمة إلى قيمة null عند البحث من البداية.
- خيارات البحث, خيارات البحث.
const path = require("path"); | |
const AsposeCells = require("aspose.cells.node"); | |
// The path to the documents directory. | |
const sourceDir = path.join(__dirname, "data"); | |
// Instantiate the workbook object | |
const workbook = new AsposeCells.Workbook(sourceDir + "sampleFindingDataOrFormulasUsingFindOptions.xlsx"); | |
workbook.calculateFormula(); | |
// Get Cells collection | |
const cells = workbook.getWorksheets().get(0).getCells(); | |
// Instantiate FindOptions Object | |
const findOptions = new AsposeCells.FindOptions(); | |
// Create a Cells Area | |
const ca = new AsposeCells.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.setSearchBackward(false); | |
findOptions.setSearchOrderByRows(true); | |
// Set the lookintype, you may specify, values, formulas, comments etc. | |
findOptions.setLookInType(AsposeCells.LookInType.Values); | |
// Set the lookattype, you may specify Match entire content, endswith, starwith etc. | |
findOptions.setLookAtType(AsposeCells.LookAtType.EntireContent); | |
// Find the cell with value | |
const cell = cells.find(341, null, findOptions); | |
if (cell !== null) { | |
console.log("Name of the cell containing the value: " + cell.getName()); | |
} else { | |
console.log("Record not found "); | |
} |
العثور على الخلايا التي تحتوي على قيمة سلسلة أو رقم محدد
من الممكن العثور على قيم نصية محددة من خلال استدعاء نفس طريقة find الموجودة في مجموعة Cells مع عدة FindOptions.
حدد خصائص FindOptions.setLookInType و FindOptions.setLookAtType. يوضح رمز المثال التالي كيفية استخدام هذه الخصائص للعثور على خلايا تحتوي على عدد مختلف من النصوص في البداية أو في المنتصف أو في النهاية لنص الخلية.
const path = require("path"); | |
const AsposeCells = require("aspose.cells.node"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
// Instantiate the workbook object | |
const workbook = new AsposeCells.Workbook(path.join(dataDir, "book1.xls")); | |
// Get Cells collection | |
const cells = workbook.getWorksheets().get(0).getCells(); | |
const opts = new AsposeCells.FindOptions(); | |
opts.setLookInType(AsposeCells.LookInType.Values); | |
opts.setLookAtType(AsposeCells.LookAtType.EntireContent); | |
// Find the cell with the input integer or double | |
let cell1 = cells.find(205, null, opts); | |
if (cell1 !== null) { | |
console.log("Name of the cell containing the value: " + cell1.getName()); | |
} else { | |
console.log("Record not found "); | |
} | |
// Find the cell with the input string | |
let cell2 = cells.find("Items A", null, opts); | |
if (cell2 !== null) { | |
console.log("Name of the cell containing the value: " + cell2.getName()); | |
} else { | |
console.log("Record not found "); | |
} | |
// Find the cell containing the input string | |
opts.setLookAtType(AsposeCells.LookAtType.Contains); | |
let cell3 = cells.find("Data", null, opts); | |
if (cell3 !== null) { | |
console.log("Name of the cell containing the value: " + cell3.getName()); | |
} else { | |
console.log("Record not found "); | |
} |