1

I have a function ApplyFormulas() that will obviously apply formulas like so

detailWs.Range(companyModel.RevenueFormulaRangeDollars).FormulaR1C1 = companyModel.RevenueFormulaDollars;

However Now I need to copy that range and paste it in the same spot so the values are real and not just formula references.

I am able to do this in VBA with excel interop but I am utilizing ClosedXML. Does anyone know of a way to do this? I tried CopyTo() but there is no paste special etc.

I also attempted

detailWs.Range(companyModel.NoChargeFormulaRangePercent).Value = detailWs.Range(companyModel.NoChargeFormulaRangePercent).Value;

but im getting a property or indexer cant be used because it lacks a getter but from what I can tell both have a get; set; property.

I've tried a couple for things and still not working..

    var test = detailWs.Range(companyModel.NoChargeFormulaRangePercent).CellsUsed();
    foreach(var c in test)
    {
        c.Value = c.Value.ToString();
    }
boo
  • 129
  • 1
  • 4
  • 12

1 Answers1

0

Here's what I created a few months ago to copy all the formulas in one worksheet to another.

Note: I am having a problem where some formulas using a Name are not correctly copying the Name because something thinks the Name(i.e. =QF00) is a reference and will change it with AutoFill. Will update when I figure it out.

cx.IXLWorksheet out_buff
cx.IXLRange src_range
cx.IXLCells tRows = src_range.CellsUsed(x => x.FormulaA1.Length > 0);

foreach (cx.IXLCell v in tRows)
{
    cell_address = v.Address.ToString();
    out_buff.Range(cell_address).FormulaA1 = v.FormulaA1;
}
Basic.Bear
  • 111
  • 1
  • 9