Replace cell contents

I have a need to replace the contents of a cell with some text. For example, I need to detect if a cell contains “=TODAY()” and replace it with “AUTODATE”, or else replace a cell containing “=cell(‘filename’)” with "AUTOFILE"


Is there a method within Aspose.Cells to do this?

Hi,

Please try the following code to fulfill your requirements.

Workbook report = new Workbook(“C:\Demo_new.xls”);
//Accessing the first worksheet in the Excel file
Worksheet reportsheet = report.Worksheets[0];
//Finding the cell containing the specified formula
Aspose.Cells.Cell replaceablecell = reportsheet.Cells.FindFormula(“=TODAY()”, null);
replaceablecell.Value = “AUTODATE”;
report.Save(“C:\Test_Demo_new_new.xls”, Aspose.Cells.SaveFormat.Excel97To2003);

You may also check these links for related topics information.
Find or Search data = http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/find-or-search-data.html
Adding Data to Cells = http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/adding-data-to-cells.html

That looks great, thanks. I’ll try it out.

Is there a way to detect similar elements in a header or footer, such as “&[DATE]”?

Hi,

At the moment our product does not support the feature to replace contents of Header or Footer. But this required is logged in our issue tracking system with an ID CELLSNET-18882. Once the feature becomes available, we will let you know.

Hi,

Please try following code:

PageSetup pageSetup = workbook.Worksheets[0].PageSetup;

for (int i = 0; i < 3; i++)

{

string header = pageSetup.GetHeader(i);

if (header != null && header != "" && header.IndexOf("&D") != -1)

{

///...

}

string footer = pageSetup.GetFooter(i);

if (footer != null && footer != "" && footer.IndexOf("&D") != -1)

{

///...

}

}