/* * Convert sheetname and zero indexed row and column pairs to an Excel style * Sheet1!$A$1:$C$5 formula reference with absolute values. */ void lxw_rowcol_to_formula_abs(char *formula, const char *sheetname, lxw_row_t first_row, lxw_col_t first_col, lxw_row_t last_row, lxw_col_t last_col) { size_t pos; char *quoted_name = lxw_quote_sheetname(sheetname); strncpy(formula, quoted_name, LXW_MAX_FORMULA_RANGE_LENGTH - 1); free(quoted_name); /* Get the end of the sheetname. */ pos = strlen(formula); /* Add the range separator. */ formula[pos++] = '!'; /* Add the first cell to the range. */ lxw_rowcol_to_cell_abs(&formula[pos], first_row, first_col, 1, 1); /* If the start and end cells are the same just return a single cell. */ if (first_row == last_row && first_col == last_col) return; /* Get the end of the cell. */ pos = strlen(formula); /* Add the range separator. */ formula[pos++] = ':'; /* Add the first cell to the range. */ lxw_rowcol_to_cell_abs(&formula[pos], last_row, last_col, 1, 1); }
/* * Convert zero indexed row and column pair to an Excel style $A$1:$C$5 * range reference with absolute values. */ void lxw_range_abs(char *range, int first_row, int first_col, int last_row, int last_col) { uint8_t pos; /* Add the first cell to the range. */ lxw_rowcol_to_cell_abs(range, first_row, first_col, 1, 1); /* If the start and end cells are the same just return a single cell. */ if (first_row == last_row && first_col == last_col) return; /* Get the end of the cell. */ pos = strlen(range); /* Add the range separator. */ range[pos++] = ':'; /* Add the first cell to the range. */ lxw_rowcol_to_cell_abs(&range[pos], last_row, last_col, 1, 1); }