I have a home-built utility to transfer data from a DataSet to an Excel spreadsheet. I want to put a formula (e.g. “=+RC[-2]-RC[-1]”) in one of the columns. However, Excel is treating it a string and not interpreting it as a formula. The utility creates and transfers an array of objects to a Range in Excel. Is this the problem? I have written formulas to Excel in the past, but only when writing to a single cell.
for (int r = 0; r < nr; r++)
{
r = dt.Rows[r];
nOut++;
aRng = new object[nc];
for (int c = 0; c < nc; c++) else aRng[c] = dr[c];
oRng = oSheet.get_Range(CellAddress(nOut, 1), CellAddress(nOut, nc));
oRng.Value2 = aRng;
}
You have to use the .Formula property in order to force excel to treat it as a formula.