SheetJS: Do Not Include Headers In json_to_sheet

Tykin picture Tykin · Nov 22, 2017 · Viewed 14.8k times · Source

The SheetJS documentation shows a way to take a JSON Object and convert it to an Excel sheet. From their example:

By default, the header information is Object.keys.

The output looks like this in excel:

excel output

My question: how do I leave out the header when converting from Json_to_sheet? I do not want the header in my output, only the numbers in the order of Object.keys.

Answer

Kishore Konangi picture Kishore Konangi · Jan 11, 2018

Please find the updated answer below:

if(typeof XLSX == 'undefined') XLSX = require('xlsx');
var wb = XLSX.utils.book_new();

var ws = XLSX.utils.json_to_sheet([
  {S:1,h:2,e:3,e_1:4,t:5,J:6,S_1:7},
  {S:2,h:3,e:4,e_1:5,t:6,J:7,S_1:8}
], {skipHeader: 1});

XLSX.utils.book_append_sheet(wb, ws, "No Header");

var wbout = XLSX.write(wb, {bookType:'xlsx', type:'array'});
saveAs(new Blob([wbout],{type:"application/octet-stream"}), "test.xlsx");

Here we can use skipHeader option inorder to skip the JSON Key values to default as a column name.