delete empty rows in xslx-js-style

69 Views Asked by At

    const wb = XLSX.utils.book_new();
        
    const data = [];
    for (let i = 0; i < 11; i++) {
      const newBody = [
        {
          v: i,
        },
      ];
      data.push(newBody);
    }

    const ws4 = XLSX.utils.aoa_to_sheet([...data]);
    
    function ec(r, c){
      return XLSX.utils.encode_cell({r:r,c:c});
    }
    function delete_row(ws, row_index){
      const variable = XLSX.utils.decode_range(ws["!ref"])
      for(let R = row_index; R < variable.e.r; ++R){
        for (let C = variable.s.c; C <= variable.e.c; ++C) {
          ws[ec(R,C)] = ws[ec(R+1,C)];
        }
      }

      variable.e.r--
      ws['!ref'] = XLSX.utils.encode_range(variable.s, variable.e);
    }
    delete_row(ws4,11)
    delete_row(ws4,10)
    delete_row(ws4,9)
    
    XLSX.utils.book_append_sheet(wb, ws4, "test");
    XLSX.writeFile(wb, "excel.xlsx");

I use xlsx-js-style in React. By using delete_row(), cell data has been erased. But there's still empty border.

enter image description here

Really want to delete rows, not only data but also border of rows.The reason I'm going to do this is because if the row remains, the user can type it in an empty row. I wish there was only one line left. So plz help me...

0

There are 0 best solutions below