2

enter image description here

I have this excel. Using Sheet JS library I want to add default values to the A column, now I have function which can add a cell

function add_cell_to_sheet(worksheet, address, value) {
    /* cell object */
    var cell = {t:'?', v:value};

    /* assign type */
    if(typeof value == "string") cell.t = 's'; // string
    else if(typeof value == "number") cell.t = 'n'; // number
    else if(value === true || value === false) cell.t = 'b'; // boolean
    else if(value instanceof Date) cell.t = 'd';
    else throw new Error("cannot store value");

    /* add to worksheet, overwriting a cell if it exists */
    worksheet[address] = cell;

    /* find the cell range */
    var range = XLSX.utils.decode_range(worksheet['!ref']);
    var addr = XLSX.utils.decode_cell(address);

    /* extend the range to include the new cell */
    if(range.s.c > addr.c) range.s.c = addr.c;
    if(range.s.r > addr.r) range.s.r = addr.r;
    if(range.e.c < addr.c) range.e.c = addr.c;
    if(range.e.r < addr.r) range.e.r = addr.r;

    /* update range */
    worksheet['!ref'] = XLSX.utils.encode_range(range);
}

This can add a cell if I provide the exact cell and value. I want to fill the missing A Cells with a default fault. I can send theM one by one.

Is there any way to find out for a given sheet how many B's are there and push them in an array and loop them to send the corresponding A cells to the Add function?

0 Answers0