I need to create a xlsx with merged cells using sheetjs.
data:
[
{
"id": "nick",
"items": [
{
"name": "ball"
},
{
"name": "phone"
}
]
},
{
"id": "jack",
"items": [
{
"name": "pen"
},
{
"name": "doll"
}
]
}
]
My code:
var ws = XLSX.utils.json_to_sheet(data);
var wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, "");
var wbout = XLSX.write(wb, {bookType:'xlsx', type:'array'});
saveAs(new Blob([wbout],{type:"application/octet-stream"}), filename + ".xlsx");
The result I want to get:
How do I get this result?
... Thank you
Right-click and then select "Format Cells" from the popup menu. When the Format Cells window appears, select the Alignment tab. Check the "Wrap text" checkbox. Now when you return to the spreadsheet, you will need to manually adjust the height of the row that contains the merged cells.
Highlight or select a range of cells. Right-click on the highlighted cells and select Format Cells.... Click the Alignment tab and place a checkmark in the checkbox labeled Merge cells.
In the table, drag the pointer across the cells that you want to merge. Click the Layout tab. In the Merge group, click Merge Cells.
You can combine two or more table cells located in the same row or column into a single cell. For example, you can merge several cells horizontally to create a table heading that spans several columns. Select the cells that you want to merge. Under Table Tools, on the Layout tab, in the Merge group, click Merge Cells.
const merge = [
{ s: { r: 1, c: 0 }, e: { r: 2, c: 0 } },{ s: { r: 3, c: 0 }, e: { r: 4, c: 0 } },
];
ws["!merges"] = merge;
Use this code for merge A2:A3 ({ s: { r: 1, c: 0 }, e: { r: 2, c: 0 } }
)
and A4:A5 ({ s: { r: 3, c: 0 }, e: { r: 4, c: 0 } }
)
Here s = start, r = row, c=col, e= end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With