how to merge cells in excel when exporting datatables?
how to merge cells in excel when exporting datatables?

When I export datatables.net to excel file I need to merge few cells. How to do it?
I tried code below, but it doesn't work:
customize: function( xlsx ) {
var sheet = xlsx.xl.worksheets['sheet1.xml'];
$('row c[r^="C2"]', sheet).attr( 'rowspan', '3' );
$('row c[r^="A5"]', sheet).attr( 'colspan', '2' );
}
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
There is no
rowspan
orcolspan
in Open Spreadsheet XML files - you need to usemergeCells
instead. This is how Buttons does it although for full details you'd need to refer to the Open Spreadsheet specifications - that is beyond the scope of DataTables.Allan
Allan, thank you for your answer. I will try with mergeCells
Allan and elen11
What should be passed in mergeCells method arguments are row and colspan?
How to call this method? Can you pls provide me the single line of sample code for it.
var mergeCells = function ( row, colspan ) {
var mergeCells = $('mergeCells', rels);
@allan and @elen11
How to use mergeCells method. Any example pls
}
HI Allan,
I am getting an exception (Uncaught TypeError: mergeCells.appendChild is not a function).
How can i solve it?
Hi @harish01 ,
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
Hi,
Thanks for the reply.
here is the fiddle
https://jsfiddle.net/xs30jz1c/1/
Your test case is not running. You are getting this error in the console:
Doesn't look like you added the jquery and datatables in JS and CSS include file. Please add those and so we can see your code generate the
Uncaught TypeError: mergeCells.appendChild is not a function
error.Kevin
@kthorngren
Hi,
Thank you for the reply.
I am having Jquery and datatables in js and css.
i want to know what this code does.
var mergeCells = $('mergeCells', sheet);
mergeCells[0].appendChild(_createNode(sheet, 'mergeCell', {
attr: {
ref: 'A1:E1'
}
}));
Thank you.
@veeray nice - thanks for posting,
Colin