Search code examples
angularxlsxxlsxwritersheetjs

How to delete a column from sheetjs with some condition using angular 4?


var ws = XLSX.utils.json_to_sheet(data);
    ws.set_column('Y1', None, None, {'hidden': True});

/* add to workbook */
var wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, 'content');

/* generate an XLSX file */
XLSX.writeFile(wb, 'test.xlsx');

}

i am exporting the json object using angular 4 like this, its giving me expected results.

But when i am trying to hide a particular column

/* hide column*/
if (this.column === 'No') {
ws.set_column('A1', None, None, {'hidden': True});

}

Here in this code it is giving me error for None, true that can not find name none and true.


Solution

  • In sheetJs there is no such set_column() function.

    If someone really delete some columns or rows can delete by map

    ex:=

    suppose you have your response in some variable called resultResposne

    this.resultResponse.map((obj) =>{
    
    
    
     if(){ 
    
        // your condition goes here
           delete obj.`your column`;
    
        }
    
    })