Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SheetJS: Do Not Include Headers In json_to_sheet

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

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}
], {header:["S","h","e","e_1","t","J","S_1"]});

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.

like image 619
Tykin Avatar asked Dec 07 '25 06:12

Tykin


1 Answers

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.

like image 98
Kishore Konangi Avatar answered Dec 10 '25 02:12

Kishore Konangi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!