البحث والاستبدال البيانات في نطاق باستخدام C++
Contents
[
Hide
]
أحيانًا تحتاج إلى البحث عن واستبدال بيانات معينة في نطاق، مع تجاهل أي قيم خلايا خارج النطاق المطلوب. يسمح لك Aspose.Cells بتقييد البحث على نطاق معين. يوضح هذا المقال كيف.
يوفر Aspose.Cells طريقة FindOptions::SetRange() لتحديد نطاق عند البحث عن البيانات. يوضح العينة البرمجية أدناه كيفية البحث واستبدال البيانات في نطاق.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Path of input excel file
U16String filePath = srcDir + u"input.xlsx";
// Create workbook
Workbook workbook(filePath);
// Get the first worksheet
Worksheet worksheet = workbook.GetWorksheets().Get(0);
// Specify the range where you want to search
// Here the range is E9:H15
CellArea area = CellArea::CreateCellArea(u"E9", u"H15");
// Specify Find options
FindOptions opts;
opts.SetLookInType(LookInType::Values);
opts.SetLookAtType(LookAtType::EntireContent);
opts.SetRange(area);
Cell cell;
do
{
// Search the cell with value search within range
cell = worksheet.GetCells().Find(u"search", cell, opts);
// If no such cell found, then break the loop
if (!cell)
break;
// Replace the cell with value replace
cell.PutValue(u"replace");
} while (true);
// Save the workbook
U16String outputPath = srcDir + u"output.out.xlsx";
workbook.Save(outputPath);
std::cout << "Workbook saved successfully!" << std::endl;
Aspose::Cells::Cleanup();
}