'Write a formula to a worksheet cell.
Args:
first_row:    The first row of the cell range. (zero indexed).
first_col:    The first column of the cell range.
last_row:     The last row of the cell range. (zero indexed).
last_col:     The last column of the cell range.
formula:      Cell formula.
cell_format:  An optional cell Format object.
value:        An optional value for the formula. Default is 0.
Returns:
0:  Success.
-1: Row or column is out of worksheet bounds.'

@convert_range_args
def write_array_formula(self, first_row, first_col, last_row, last_col, formula, cell_format=None, value=0):

    if (first_row > last_row):
        (first_row, last_row) = (last_row, first_row)
    if (first_col > last_col):
        (first_col, last_col) = (last_col, first_col)
    if self._check_dimensions(last_row, last_col):
        return (-1)
    if ((first_row == last_row) and (first_col == last_col)):
        cell_range = xl_rowcol_to_cell(first_row, first_col)
    else:
        cell_range = ((xl_rowcol_to_cell(first_row, first_col) + ':') + xl_rowcol_to_cell(last_row, last_col))
    if (formula[0] == '{'):
        formula = formula[1:]
    if (formula[0] == '='):
        formula = formula[1:]
    if (formula[(-1)] == '}'):
        formula = formula[:(-1)]
    if (self.constant_memory and (first_row > self.previous_row)):
        self._write_single_row(first_row)
    self.table[first_row][first_col] = cell_arformula_tuple(formula, cell_format, value, cell_range)
    if (not self.constant_memory):
        for row in range(first_row, (last_row + 1)):
            for col in range(first_col, (last_col + 1)):
                if ((row != first_row) or (col != first_col)):
                    self.write_number(row, col, 0, cell_format)
    return 0
