Sheetjs: Generate Excel sheet with Headings

Created on 7 Jan 2018  Â·  4Comments  Â·  Source: SheetJS/sheetjs

Hi all,
How I can get data in the following format

Employee Details
Emp Name Emp Sal
xyz 1000
abc 2000

Any help would be appreciated.

Most helpful comment

https://jsfiddle.net/hsgosmp5/ live example:

var Heading = [
  ["Employee Details"],
  ["Emp Name", "Emp Sal"]
];
var Data = [
  {name:"xyz", sal:1000},
  {name:"abc", sal:2000}
];
var ws = XLSX.utils.aoa_to_sheet(Heading);
XLSX.utils.sheet_add_json(ws, Data, {
  header:["name", "sal"],
  skipHeader:true,
  origin:-1
 });

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

All 4 comments

https://jsfiddle.net/hsgosmp5/ live example:

var Heading = [
  ["Employee Details"],
  ["Emp Name", "Emp Sal"]
];
var Data = [
  {name:"xyz", sal:1000},
  {name:"abc", sal:2000}
];
var ws = XLSX.utils.aoa_to_sheet(Heading);
XLSX.utils.sheet_add_json(ws, Data, {
  header:["name", "sal"],
  skipHeader:true,
  origin:-1
 });

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

Thank you, saved my day

On Jan 9, 2018 10:09 PM, "reviewher" notifications@github.com wrote:

https://jsfiddle.net/hsgosmp5/ live example:

var Heading = [
["Employee Details"],
["Emp Name", "Emp Sal"]
];var Data = [
{name:"xyz", sal:1000},
{name:"abc", sal:2000}
];var ws = XLSX.utils.aoa_to_sheet(Heading);XLSX.utils.sheet_add_json(ws, Data, {
header:["name", "sal"],
skipHeader:true,
origin:-1
});
var wb = XLSX.utils.book_new();XLSX.utils.book_append_sheet(wb, ws, "SheetJS");var wbout = XLSX.write(wb, {bookType:'xlsx', type:'array'});saveAs(new Blob([wbout],{type:"application/octet-stream"}), "issue946.xlsx");

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/SheetJS/js-xlsx/issues/946#issuecomment-356339743,
or mute the thread
https://github.com/notifications/unsubscribe-auth/Aeb8FLPhPhSbBUK-TG8Z73DfKe4NlLYsks5tI5X1gaJpZM4RVimp
.

Hi,

I got other requirement where, I need to show excel data saved in multiple sheets as follows

In first sheet(Named Staff Details) I need to store the data as follows

Assistant Professor(Heading)
Name Sal
xyz 20000
abc 30000

Associate Professor(Heading)
Name Sal
xyz123 40000
abc123 50000

In Second Sheet(Named Student Details) I need to store the data as follows

Student Details
Name Roll No
xyz 101
abc 102

Can you please help me how to achieve this.

@rajuyadav-orchestratec were you able to achieve your last requirement?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sudhakar-sekar picture sudhakar-sekar  Â·  3Comments

happy0088 picture happy0088  Â·  3Comments

Alex0007 picture Alex0007  Â·  3Comments

gustavosimil picture gustavosimil  Â·  3Comments

eyalcohen4 picture eyalcohen4  Â·  3Comments