Veri Bulma veya Arama

Belirli Verileri İçeren Hücreleri Bulma

Microsoft Excel Kullanımı

Microsoft Excel, belirli veriyi içeren hücreleri bulma imkanı sağlar. Microsoft Excel’de İşle menüsünden Bul seçildiğinde, arama değerini belirtebileceğiniz bir iletişim kutusu göreceksiniz.

Burada, “Portakallar” değerini arıyoruz. Aspose.Cells, ayrıca belirli değerleri içeren hücreleri bulmayı sağlar.

Aspose.Cells for Node.js via C++ kullanımıyla

Aspose.Cells, Microsoft Excel dosyasını temsil eden Workbook sınıfını sağlar. Workbook sınıfı, Excel dosyasındaki her çalışma sayfasına erişim sağlayan Workbook.getWorksheets() koleksiyonunu içerir. Bir çalışma sayfası Worksheet sınıfı ile temsil edilir. Worksheet sınıfı, çalışma sayfasındaki tüm hücreleri temsil eden getCells() koleksiyonunu sağlar. Cells koleksiyonu, kullanıcı tarafından belirlenen verileri içeren hücreleri bulmak için çeşitli yöntemler sunar. Bu yöntemlerden birkaçını detaylıca aşağıda görebilirsiniz.

Formül İçeren Hücreleri Bulma

Geliştiriciler, belirli bir formülü Cells koleksiyonunun find yöntemiyle bulabilirler. Genellikle, find metodu üç parametre alır:

  • Obje: Aranacak nesne. Türü int, double, DateTime, string, bool olmalı.
  • Önceki hücre: Aynı nesneye sahip önceki hücre. Aramaya başlarken null olarak ayarlanabilir.
  • FindOptions: Aranan nesne için seçenekler.

Aşağıdaki örnekler, bulma yöntemlerini uygulamak için çalışma sayfası verilerini kullanır:

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 Kullanarak Veri veya Formülleri Bulma

Belirtilen değerleri, Cells koleksiyonunun Cells.find(object, Cell) metodu ve çeşitli FindOptions parametrelerle bulmak mümkündür. Genellikle, find metodu şu parametreleri kabul eder:

  • Arama değeri, aranmak istenen veri veya değer.
  • Önceki hücre, aynı değere sahip son hücre. Aramaya başlangıçtan itibaren arıyorsanız bu parametre null olarak ayarlanabilir.
  • Bul seçenekleri, bul seçenekleri.
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 ");
}

Belirli Dize Değeri veya Numarası İçeren Hücreleri Bulma

Belirli dizgi değerleri, aynı find metodunu farklı FindOptions parametreleriyle çağırarak bulunabilir.

FindOptions.setLookInType ve FindOptions.setLookAtType özelliklerini belirtin. Aşağıdaki örnek kod, bu özelliklerin nasıl kullanılacağını gösterir ve hücrenin başında, ortasında veya sonunda çeşitli sayıda dizge içeren hücreleri bulmak için kullanılır.

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

Gelişmiş Konular