Create excel formula in C# code
Posted on 2011-03-22
I have an app that creates excel workbooks, filling with data, graphs etc no problem.
I now want to create a formula on Sheet2 that references a cell on Sheet1.
I can do it no problem with the following line of code
worksheet.get_Range(worksheet.Cells[curRowIx, curColIx], worksheet.Cells[curRowIx, curColIx]).Formula = "='SN21'!C" + startRow;
using the startRow in the formula i can loop through the rows no problem and it works. What i need is to be able to access the column in a loop also. Not using C1 but R[x]C[y] so i can loop through all data i need and populate the formulas correctly.
I know i can hardcode all the A1, B1 ... etc but that makes me nauseous and i hate repetitive code. I want to use something like
.Formula = "='SN21'" + worksheet.Cells[curRowIx, curColIx] but i cant get it to work
Thanks in advance