locked
Excel Interop - setting formula for a cell RRS feed

  • Question

  • User1909955381 posted

    I'm create an excel spreadsheet dynamically using Excel Interop.

    I have two cells in a single column.

    The first cell contains this formula: "=(F1+G1)"

    I would like to set the formula for the second cell to be the same as the first cell, but have F2 and G2 instead of F1 and G1.  This needs to be dynamic.

    Here's what I have now:

    Excel.Range rngCurrentCell = (Excel.Range)ws.Cells[row,col];
    Excel.Range rngPrevRow = (Excel.Range)ws.Cells[row - 1, col];
    
    rngCurrentCell.Formula = rngPrevRow.Formula;


    I thought the code above would work, but that just sets the second cell to have the formula: "=(F1+G1"


    Friday, August 21, 2009 3:58 PM

All replies

  • User1918990383 posted


    In the Excel, if you drag the a formula, then automatically increment happens for the cell.

    If you cut and paste the same formula to some other cell then it works.

    Monday, August 24, 2009 8:23 AM