sheetjs icon indicating copy to clipboard operation
sheetjs copied to clipboard

How to skip rows?

Open fpasxos opened this issue 8 years ago • 2 comments

Hello everyone, I hope that this is the right topic to open a thread. I am currently new on using the library, so I have a quick question.

Is there a way to write the first three rows with some info, and afterwards add the excel data? I am attaching a screenshot of some sort of desired outcome.

image

In the picture above, aaaaa-bbbbb-ccccc are some random data, and x,y,z are the column names and the numbers below them are the data. Is there any way to achieve that?

Thanks a lot for your time.

fpasxos avatar Jan 08 '18 12:01 fpasxos

We added a few helper functions for adding to an existing worksheet. Here's one way to reproduce your screenshot:

/* generate a new workbook with the first three rows */
var ws = XLSX.utils.aoa_to_sheet([
	["aaaaaa"],
	["bbbbb"],
	["cccccc"]
]);

/* this array controls the column order in the generated sheet */
var header = ["x", "y", "z"];

/* add row objects to sheet starting from cell A6 */
XLSX.utils.sheet_add_json(ws, [
	{x:1, y:2, z:3},
	{x:435, y:345, z:54}
], {header:header, origin:"A6"});

/* append two more rows without header */
XLSX.utils.sheet_add_json(ws, [
	{x:345, y:345, z:345},
	{x:345, y:3, z:345}
], {header:header, origin:-1, skipHeader:true});

https://jsfiddle.net/re2x441s/ is a live example that generates an XLSX workbook

SheetJSDev avatar Jan 09 '18 08:01 SheetJSDev

adamsın uleyyn. Good job. You are best coder. @SheetJSDev

yvzkr avatar Feb 23 '20 17:02 yvzkr