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

Free Support Forum - aspose.com

Replace method not working

I’m using the Replace method to overlay placeholders in a designer file. It works for several of the cells on the designer but others simple have #value! in the cell. I checked the format of the cells to verify I wasn’t having any datatype issues and I don’t believe that to be the cause. Also, when I open the saved xls file I get a file error, data may be lost. Any ideas on what to check?

Thanks, Donta

Hi Donta,

Could you send me your designer file and you relative code? That may greatly help me to investigate the problem.

Thanks for your cooperation.

I believe I see what is happening. The following code will create the error every time.
exObj.Replace("&Sports",“N”)
exObj.Replace("&News",“N”)
exObj.Replace("&Weather",“N”)
The &Sports placeholder will correcly populate but &News and &Weather will show #Value! in the cell and the spreadsheet has an error. However, if I change the code to the following then everything works properly:
exObj.Replace("&Sports",“N”)
exObj.Replace("&News",“N1”)
exObj.Replace("&Weather",“N2”)

I can send a designer file with these 3 placeholders if it’s required. I just need to know where to send it.

Thanks, Donta

Just send it to excel@aspose.com.

Hi,

It’s fixed. A new hotfix will be released tomorrow.

@donta,
Please note that Aspose.Cells is introduced which has replaced the previous product Aspose.Excel. Using this new product Aspose.Cells you can perform variety of exciting tasks which may enhance your products a lot. This new product also supports searching and replacing text as demonstrated below:

Workbook workbook = new Workbook(filePath);

Worksheet worksheet = workbook.Worksheets[0];

// Specify the range where you want to search
// Here the range is E3:H6
CellArea area = CellArea.CreateCellArea("E9", "H15");

// Specify Find options
FindOptions opts = new FindOptions();
opts.LookInType = LookInType.Values;
opts.LookAtType = LookAtType.EntireContent;
opts.SetRange(area);

Cell cell = null;

do
{
    // Search the cell with value search within range
    cell = worksheet.Cells.Find("search", cell, opts);

    // If no such cell found, then break the loop
    if (cell == null)
        break;

    // Replace the cell with value replace
    cell.PutValue("replace");

} while (true);

// Save the workbook
workbook.Save(dataDir+ "output.out.xlsx");

A detailed article is mentioned below which provides all the details and sample codes about this issue:
Search and Replace Data in Range
Replace Text in Smart Art

Here is link to the latest veersion of this product:
Aspose.Cells for .NET (Latest Version)

A rich working solution is available here for testing different features of this new product.