Range.Replace equalent in Aspose.cells

hi

what is the "Range.Replace" equalent in Aspose.cell.That is i have a variable in Excel and i need to replace that variable with some value.In Aspose.Word i have used "Range.Replace" and i need the equalent in Aspose.cell

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

From your description, I think, Smart Marker features will fullfill your needs.

You put smart marker tags in an input file then these tags are replaced with actual values that are present in your database/datatables.

Please see this article for your more help.

Smart Markers

Hi,


Well, if you need to simply find and replace options to replace some value with other value in a worksheet or workbook, we provide Worksheet.Replace() and Workbook.Replace() methods to replace the values in a worksheet or even in the whole workbook, see the sample code below:

Sample code:

Workbook wb = new Workbook(“e:\test\casesensitive\test.xls”);
wb.Open(“e:\test\\replacetest.xls”);
ReplaceOptions replace = new ReplaceOptions();
replace.CaseSensitive = false;
replace.MatchEntireCellContents = false;
wb.Replace(“officialName”, “mmAwesome Agency”,replace);
wb.Save(“e:\test\out_test.xls”);


Moreover, you may try to find your desired value in a cell area using FindXXXX methods of Cells class, you may easily replace your found cell’s values with your desired values using String.Replace() method accordingly.
See the document for reference here.
http://www.aspose.com/docs/display/cellsnet/Find+or+Search+Data

Also, see another sample code for your reference for finding and replacing a value using FindXXX method of Cells class:

Sample code:

Workbook workbook = new Workbook(@"e:\test\FindStringContains1.xls");
WorksheetCollection worksheets = workbook.Worksheets;
string stringtofind = "Test";
string stringtoreplace = "Rock";
for (int i = 0; i < worksheets.Count; i++)
{

Worksheet worksheet = workbook.Worksheets[i];
Cells cells = worksheet.Cells;
Cell cell;
Cell prevcell = null;

do
{
cell = cells.FindStringContains(stringtofind, prevcell);
if (cell == null)
break;
string val = cell.StringValue.Replace(stringtofind, stringtoreplace);
cell.PutValue(val);
prevcell = cell;

} while (cell != null);

}
workbook.Save("e:\\test\\FindStringContains_test_out.xls");



Thank you.


Hi
I want to repleace a character (for excaple “a”) with another character (“b”) in a whole worksheet…
above code replace the value of a cell completely … I just want to replace a character not whole the cells…
which code I should use?
thanks a lot

@hamed0isu,
You may use following sample code and share the feedback.

Workbook wb = new Workbook(@"book1.xlsx");
Worksheet ws = wb.Worksheets[0];
ws.Replace("a", "b");
wb.Save(@"book2.xlsx");