worksheet_write_formula

@brief Write a formula to a worksheet cell.

@param worksheet pointer to a lxw_worksheet instance to be updated. @param row The zero indexed row number. @param col The zero indexed column number. @param formula Formula string to write to cell. @param format A pointer to a Format instance or NULL.

@return A #lxw_error code.

The %worksheet_write_formula() function writes a formula or function to the cell specified by row and column:

@code worksheet_write_formula(worksheet, 0, 0, "=B3 + 6", NULL); worksheet_write_formula(worksheet, 1, 0, "=SIN(PI()/4)", NULL); worksheet_write_formula(worksheet, 2, 0, "=SUM(A1:A2)", NULL); worksheet_write_formula(worksheet, 3, 0, "=IF(A3>1,\"Yes\", \"No\")", NULL); worksheet_write_formula(worksheet, 4, 0, "=AVERAGE(1, 2, 3, 4)", NULL); worksheet_write_formula(worksheet, 5, 0, "=DATEVALUE(\"1-Jan-2013\")", NULL); @endcode

@image html write_formula01.png

The format parameter is used to apply formatting to the cell. This parameter can be NULL to indicate no formatting or it can be a @ref format.h "Format" object.

Libxlsxwriter doesn't calculate the value of a formula and instead stores a default value of 0. The correct formula result is displayed in Excel, as shown in the example above, since it recalculates the formulas when it loads the file. For cases where this is an issue see the worksheet_write_formula_num() function and the discussion in that section.

Formulas must be written with the US style separator/range operator which is a comma (not semi-colon). Therefore a formula with multiple values should be written as follows:

@code // OK. worksheet_write_formula(worksheet, 0, 0, "=SUM(1, 2, 3)", NULL);

// NO. Error on load. worksheet_write_formula(worksheet, 1, 0, "=SUM(1; 2; 3)", NULL); @endcode

extern (C)
worksheet_write_formula

Meta