Skip to content

Easier way to write custom formula functions #214

@binyomen

Description

@binyomen

I've just started using formulas, and I really like them! However, I've been having trouble writing custom functions that take a range like Max, Sum, etc.

In #114 (comment), you provide an example where the function SumTime takes in the range as a string, then converts it to a list with GetCellRange. This only seems to work if your cursor is in that column, however, since GetCellRange uses the cursor position if a line and column number aren't provided. This doesn't match the behavior of the builtin functions, which decide the the column based on the cell you're setting (if it isn't explicit).

I've been trying to figure out how to pass in the correct line and column number similarly to the builtin functions, but I haven't been able to find a way to do that. The closest I've gotten is copying a bunch of code from EvaluateFormulaLine to get the correct line, but I don't have easy access to the actual formula line itself to parse out the column. I have tried passing in the column manually in the range, like '1,4:-1,4' instead of '1:-1', and that works but only if the cursor is somewhere on the table. If the cursor is on the formula line, it produces an empty range.

It's very possible I'm missing something here, but if I'm not it would be really great to have an easier way to implement these kind of functions. Or at least documentation on the "hard" way to do it.

Thanks so much!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions