Copy formula

Hi

I am using Aspose.Grid version 1.9.2.0

When I try to copy formula from one cell to another eg sheet.cells(0,0).formula = sheet.cells(1,1).formula

I get the following error - Property 'Formula' is Read Only

Can you advise

Regards

Bob Hamill

Hi,

Well, the WebCell.Formula property is (get,set) and I don't find the problem you are mentioning, It works fine here. Since you are using some older version of Aspose.Grid.Web, Please try upgrade to the latest versions like 1.9.2.8 downloading from the thread: <A href="</A> </P> <P>Thank you.</P> <P> </P>

Hi - it is Desktop Grid I am using - version 1.9.2.0

When I try to copy formula from one cell to another eg sheet.cells(0,0).formula = sheet.cells(1,1).formula

I get the following error - Property 'Formula' is Read Only

Can you advise

Hi,

Well, GridCell.Formula is indeed a read-only property, it is just used to get the formula of a cell. Please use:

  • GridCell.Value (property).........Gets or sets a cell value. If value is formula, the set method of this property will call GridDesktop.RunAllFormulas method automatic. So, if there are many formulas, using SetCellValue method instead of this property. SetCellValue method will enhance performance.
  • GridCell.SetCellValue() (method).............If the value is a formula,this method set cell's value as FormulaType, but not calculate formula. To calculate formula,need call GridDesktop.RunAllFormulas manually. If multi values to be set,call this method multi times, finally,call GridDesktop.RunAllFormulas method manually to calculate formulas. This is more effective.

Examples:

1. Dim cell As GridCell = gridDesktop1.Worksheets(0).Cells(0,0)
'Setting the formula to the A1 cell from B2 cell and also automatically calculates it.
cell.Value = gridDesktop1.Worksheets(0).Cells(1, 1).Formula
'OR
2. Dim cell As GridCell = gridDesktop1.Worksheets(0).Cells(0,0)
'Setting the formula to A1 cell from B2 cell.
cell.SetCellValue(gridDesktop1.Worksheets(0).Cells(1, 1).Formula)
'Use this line if you also wants to calculate the formula.
gridDesktop1.RunAllFormulas()