We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Raplace cell value on a range

Hi,

I want to replace some value in a range, not worksheet or workbook level, do we have such method? Such like:

ReplaceOptions ro = new ReplaceOptions();
ro.setCaseSensitive(false);
ro.setMatchEntireCellContents(true);

Range r=worksheet.getCells.createRange(0, 0, 18, 6);

r.replace(oldString, newString, ro);

Thanks.

Hi,


I have created a sample code to accomplish your task using current Aspose.Cells APIs, so you may refer to it and create your own codes accordingly.
e.g
Sample code:

String path = “f:\files\sourceBk1.xlsx”;

Workbook workbook = new Workbook(path);

String stringtofind = “test”;
String stringtoreplace = “Value”;

Worksheet worksheet = workbook.getWorksheets().get(0);
Cells cells = worksheet.getCells();
Cell cell;
Cell prevcell = null;
FindOptions opts = new FindOptions();
opts.setLookAtType(LookAtType.ENTIRE_CONTENT);
opts.setLookInType(LookInType.VALUES);
opts.setCaseSensitive(false);
CellArea ca = new CellArea();
ca.StartRow = 0;
ca.StartColumn = 0;
ca.EndRow = 18;
ca.EndColumn = 6;

opts.setRange(ca);

do {
cell = cells.find(stringtofind, prevcell, opts);

if (cell == null)
break;

String val = cell.getStringValue();

val = val.replace(stringtofind, stringtoreplace);

cell.setValue(val);
prevcell = cell;

} while (cell != null);

workbook.save(path + “.out1.xlsx”);

Hope, this helps a bit.

Thank you.

Thanks for your quick reply.

It works now.

Hi,


Good to know that it figures out your issue/ needs. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

Thank you.