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

Free Support Forum - aspose.com

Paste Special Values

I have a cell with a formula. I'd like to change it so I just stores the calculated value.

In Excel, I would just copy the cell and then choose Edit > Paste Special > Values. This would remove the formula and keep the resulting value.

How can I do this in Aspose.Cells?

Hi,

Thanks for considering Aspose.

Well, you may call Workbook.CalculateFormula() method and replace the cell's value with the formula string by inputing the calculated value.

May the following code help you for you need, kindly consult it. In the example, suppose we have two formulated cell in the first worksheet i.e., A10 and G1, I will remove the formulas on those cells and input the calculated values only.

Workbook workbook = new Workbook();
workbook.Open("d:\\test\\bkform.xls");
Worksheet worksheet = workbook.Worksheets[0];
Cells cells = worksheet.Cells;
//First Calculate all the formulas.
workbook.CalculateFormula(false);
//Get the formulated cell.
Cell cell1 = cells["A10"];
//Replace by the calculated value, the formula of the cell
//will be eliminated.
cell1.PutValue(cell1.IntValue);
//Get the formulated cell.
Cell cell2 = cells["G1"];
//Replace by the calculated value, the formula of the cell
//will be eliminated.
cell2.PutValue(cell2.StringValue);

workbook.Save("d:\\test\\bkform1.xls");

Thank you.