TX Text Control .NET for Windows Forms

Formula Functions

Topic

SUM, ROUND, IF and 82 other functions do most of the work in a table formula of a Windows Forms TextControl. The tables below give each function's arguments, the value an omitted argument takes and what the function returns, for formulas set with TableCell.Formula in code and for formulas users build on the Formulas tab of the ribbon. A last section lists the Excel functions Text Control names for worksheets loaded from XLSX files.

How a formula is put together, how it addresses cells and how its result is formatted is described in Tables and Table Formulas. Excel formulas in tables are part of the Enterprise and Professional editions, as Editions and Feature Availability shows.

How to Read the Tables

The functions are those of Office Open XML, ISO/IEC 29500-1, section 18.17.7, Predefined Function Definitions. That section describes the types of the arguments, their restrictions and the return values in full. The signatures below are written this way:

  • Square brackets mark an optional argument. LOG(x[,base]) is called as LOG(100) or as LOG(8,2), and the description says which value is used when the argument is left out.
  • argument-list stands for one or more arguments, separated by commas. Each one is a constant, a cell reference, a range such as A1:A3, an array constant such as {1,2,3} or the result of another function.
  • array and reference stand for a range or a single cell reference.

At runtime, TableCollection.SupportedFormulaFunctions returns the names of the supported functions, which the reference describes as the functions of these tables.

Mathematical and Trigonometric Functions

FunctionDescription
ABS(x)The absolute value of x.
ACOS(x)The arc cosine of x.
ACOSH(x)The inverse hyperbolic cosine of x.
ASIN(x)The arc sine of x.
ASINH(x)The inverse hyperbolic sine of x.
ATAN(x)The arc tangent of x.
ATAN2(x,y)The arc tangent of the coordinates x and y.
ATANH(x)The inverse hyperbolic tangent of x.
CEILING(x,significance)x rounded up, away from zero, to the nearest multiple of significance. Negative values are rounded away from zero too.
COMBIN(number,number-chosen)How many groups of number-chosen objects can be formed from number objects.
COS(x)The cosine of x.
COSH(x)The hyperbolic cosine of x.
DEGREES(angle)angle, given in radians, in degrees.
ECMA.CEILING(x,significance)x rounded up, away from zero, to the nearest multiple of significance, the same as CEILING.
EVEN(x)x rounded away from zero to the nearest even integer.
EXP(x)e to the power of x, where e is the base of the natural logarithm.
FACT(x)The factorial of x.
FACTDOUBLE(n)The double factorial of n.
FLOOR(x,significance)x rounded down, toward zero, to the nearest multiple of significance.
GCD(argument-list)The greatest common divisor of one or more numbers.
INT(x)x rounded down to an integer.
ISO.CEILING(x[,significance])x rounded up to the nearest multiple of significance, whether x is positive or negative. Without significance, 1 is used.
LCM(argument-list)The least common multiple of one or more numbers.
LN(x)The natural logarithm of x.
LOG(x[,base])The logarithm of x to base. Without base, 10 is used.
LOG10(x)The logarithm of x to base 10.
MOD(x,y)The remainder of x divided by y, with the sign of y.
MROUND(x,multiple)x rounded away from zero to a multiple of multiple: up when the remainder of x divided by multiple is half of multiple or more, down otherwise.
MULTINOMIAL(argument-list)The factorial of the sum of the values divided by the product of their factorials.
ODD(x)x rounded away from zero to the nearest odd integer.
PI()The number π.
POWER(x,y)x to the power of y.
PRODUCT(argument-list)The numeric values of the arguments multiplied.
QUOTIENT(dividend,divisor)The integer part of dividend divided by divisor.
RADIANS(angle)angle, given in degrees, in radians.
RAND()An evenly distributed random real number that is 0 or more and less than 1.
RANDBETWEEN(lower-bound,upper-bound)A random integer from lower-bound to upper-bound.
ROUND(x,number-digits)x rounded to number-digits digits.
ROUNDDOWN(x,number-digits)x rounded down, toward zero, to number-digits digits.
ROUNDUP(x,number-digits)x rounded up, away from zero, to number-digits digits.
SERIESSUM(input-value,initial-power,step,coefficients)The sum of a power series.
SIGN(x)The sign of x.
SIN(x)The sine of x.
SINH(x)The hyperbolic sine of x.
SQRT(x)The positive square root of x.
SQRTPI(x)The positive square root of x times π.
SUM(argument-list)The numeric values of the arguments added up.
SUMSQ(argument-list)The squares of the arguments added up.
SUMX2MY2(array-1,array-2)The sum of the differences between the squares of corresponding numbers of two arrays.
SUMX2PY2(array-1,array-2)The sum of the sums of the squares of corresponding numbers of two arrays.
SUMXMY2(array-1,array-2)The sum of the squared differences between corresponding numbers of two arrays.
TAN(x)The tangent of x.
TANH(x)The hyperbolic tangent of x.
TRUNC(x[,number-digits])x cut off after number-digits decimal places.

Statistical Functions

FunctionDescription
AVERAGE(argument-list)The arithmetic mean of the numeric values of the arguments.
COUNT(argument-list)How many arguments are numbers, plus how many referenced cells hold numbers. Dates aren't counted.
COUNTA(argument-list)How many arguments aren't cell references, plus how many referenced cells aren't empty. Dates in arrays and in referenced cells aren't counted.
COUNTBLANK(cell-range)How many cells of a range are empty. A cell with a formula that returns an empty string isn't counted.
MAX(argument-list)The largest of a set of numbers.
MAXA(argument-list)The largest of a set of numbers.
MIN(argument-list)The smallest of a set of numbers.
MINA(argument-list)The smallest of a set of numbers.

Logical Functions

FunctionDescription
AND(argument-list)TRUE when every argument is TRUE. Every argument is evaluated before the result is returned.
FALSE()FALSE, the same value as the logical constant FALSE.
IF(logical-value,[value-if-true][,[value-if-false]])value-if-true, evaluated and returned when logical-value is TRUE, and value-if-false otherwise.
NOT(logical-value)The opposite of logical-value.
OR(argument-list)TRUE when one or more arguments are TRUE. Every argument is evaluated before the result is returned.
TRUE()TRUE, the same value as the logical constant TRUE.

Lookup and Reference Functions

FunctionDescription
ADDRESS(row-number,col-number[,[ref-type][,[A1-ref-style-flag][,sheet-name]]])The address of the cell at row-number and col-number, as text.
CHOOSE(index,argument-list)The argument of argument-list at the position index.
COLUMN([reference])The column number of reference. Without reference, the column of the cell with the formula.
COLUMNS(array)How many columns array has. array can only be a cell reference or a range.
ROW([reference])The row number of reference. Without reference, the row of the cell with the formula.
ROWS(array)How many rows array has. array can only be a cell reference or a range.

Information Functions

FunctionDescription
ISBLANK(value)Whether value refers to an empty cell.
ISEVEN(value)Whether value is an even number or refers to a cell with an even number.
ISLOGICAL(value)Whether value is a logical value or refers to a cell with one.
ISNONTEXT(value)Whether value is something other than text and doesn't refer to a cell with text. An empty cell isn't text.
ISNUMBER(value)Whether value is a number or refers to a cell with a number.
ISODD(value)Whether value is an odd number or refers to a cell with an odd number.
ISREF(value)Whether value is a cell reference.
ISTEXT(value)Whether value is text or refers to a cell with text.
N(value)value as a number. For a reference to one cell, the value of that cell as a number.
NA()The error value #N/A. Writing #N/A in the formula gives the same result.
TYPE(value)The type of value. For a reference to one cell, the type of the value in that cell.

Excel Functions in Loaded Worksheets

StreamType.SpreadsheetML loads a worksheet of an XLSX file as a table, as Supported File Formats shows, and the table keeps the Excel compatible formulas of the worksheet. Text Control lists these 55 Excel functions as supported in them:

GroupFunctions
Mathematical and trigonometric (47)ABS, ACOS, ACOSH, ASIN, ASINH, ATAN2, ATANH, CEILING, COMBIN, COS, COSH, DEGREES, ECMA.CEILING, EVEN, EXP, FACT, FACTDOUBLE, FLOOR, GCD, INT, ISO.CEILING, LCM, LN, LOG, LOG10, MOD, MROUND, ODD, PI, POWER, PRODUCT, QUOTIENT, RADIANS, RAND, RANDBETWEEN, ROUND, ROUNDDOWN, ROUNDUP, SIGN, SIN, SINH, SQRT, SQRTPI, SUM, SUMIF, TAN, TANH
Statistical (6)AVERAGE, AREAS, MAX, MAXA, MIN, MINA
Lookup and reference (2)ADDRESS, ROW

All of them but two are in the tables above, with the same meaning. The two that aren't are these:

FunctionWhat it does
SUMIFApplies selection criteria to the values of one range of cells and adds up the values of the corresponding cells of another range.
AREASThe number of areas that a reference designates.

Because SupportedFormulaFunctions is documented to return the functions of the tables above, it isn't documented to contain SUMIF and AREAS. Before your application relies on either in a worksheet, check the list at runtime. The following method of Form1.cs shows how many functions the TextControl on the form supports and whether SUMIF is one of them:

using System;
using System.Linq;
using System.Windows.Forms;
using TXTextControl;

public partial class Form1 : Form
{
    private void ShowSupportedFunctions()
    {
        string[] functions = textControl1.Tables.SupportedFormulaFunctions;

        MessageBox.Show($"{functions.Length} functions, SUMIF supported: {functions.Contains("SUMIF")}");
    }
}

The code works as follows:

  • TextControl.Tables returns the TableCollection of the main text, or of the header, footer or text frame the user is editing.
  • SupportedFormulaFunctions is read-only and returns the function names as a string array. Contains comes from System.Linq.