Daniel's answer should work, but itβs easier for me to work with formulas in the R1C1 format. Your code should look like this:
ws.Range(range).FormulaR1C1 <- [| "=sum(R1C1:R10C1)"; "=min(R1C1:R10C1)"; "=max(R1C1:R10C1)" |]
This will generate a formula with absolute addresses. You can create relative addresses using R [vertical_offset] C [horizontal_offset]. Selecting an entire row or column is also simple: R1 is the whole first row, C4 is the full column "D".
R1C1 strings are easily simple using String.Format or sprintf in pure F #.
EDIT: I quickly checked vba, this will not work. Excel places the first element of the array in each cell of the range. In any case, the address point R1C1 remains valid. It works like a charm for header formulas (i.e. Ws.Range (headerRange) .FormulaR1C1 <- "= sum (R2C [0]: R10C [0]"), so I will leave the answer intact.
EDIT2: I think ArrayFormula is for an array formula , so it won't work either.
EDIT3: I did some research and found an answer to something that I thought was impossible :).
First, to put these lines in formulas, drag them into the object:
let formulas : obj[] = [| "=sum(R1C1:R10C1)"; "=min(R1C1:R10C1)"; "=max(R1C1:R10C1)" |]
and then put it in FormulaR1C1:
ws.Range(range).FormulaR1C1 <- formulas
Secondly, the important part: in the above example, it is assumed that the range is the horizontal range of three cells (i.e. F3: H3). If you try to place it in a vertical range (for example, F3: F5), you will notice that this sum formula is repeated in each cell of the range. I am sure that in this case the formulas should be a two-dimensional array of objects, and the first line of the external array is an array of formulas, but I get SafeArrayTypeObjectExtension, trying to put it in a range. FormulaR1C1. Take a look at this msdn file :
If the range is a one- or two-dimensional range, you can set the formula to a Visual Basic array of the same size. Similarly, you can put the formula in a Visual Basic array.
I will consider this exception again.