JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jq-3.2.1/jszip-2.5.0/dt-1.10.16/b-1.5.1/b-html5-1.5.1/b-print-1.5.1/datatables.min.css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/pdfmake.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/vfs_fonts.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/jq-3.2.1/jszip-2.5.0/dt-1.10.16/b-1.5.1/b-html5-1.5.1/b-print-1.5.1/datatables.min.js"></script>
<meta charset=utf-8 />
<title>DataTables - JS Bin</title>
</head>
<body>
<div class="container">
<table id="example" class="table table-bordered display" cellspacing="0" width="100%">
<thead>
<tr>
<th>COL 1</th>
<th>COL 2</th>
<th>COL 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>LINE 1<br>LINE 2</td>
<td><p>LINE 1</p><p>LINE 2</p></td>
<td><div>LINE 1</div><div>LINE 2</div></td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
JavaScript
$(document).ready( function () {
var table = $('#example').DataTable({
dom: 'Btirp',
buttons: [
{
extend: 'excelHtml5',
text: 'Excel',
exportOptions: {
format: {
body: function ( data, row, column, node ) {
//need to change double quotes to single
data = data.replace( /"/g, "'" );
//split at each new line
splitData = data.split('<br>');
data = '';
for (i=0; i < splitData.length; i++) {
//add escaped double quotes around each line
data += '\"' + splitData[i] + '\"';
//if its not the last line add CHAR(13)
if (i + 1 < splitData.length) {
data += ', CHAR(10), ';
}
}
//Add concat function
data = 'CONCATENATE(' + data + ')';
return data;
}
}
},
customize: function( xlsx ) {
var sheet = xlsx.xl.worksheets['sheet1.xml'];
var firstExcelRow = 3;
table.rows({order: 'applied', search: 'applied'}).every( function ( rowIdx, tableLoop, rowLoop ) {
$('c[r=A' + ( firstExcelRow + rowLoop ) + ']', sheet).each(function(e) {
if ($('is t', this).text()) {
//wrap text
$(this).attr('s', '55');
//change the type to `str` which is a formula
$(this).attr('t', 'str');
//append the concat formula
$(this).append('<f>' + $('is t', this).text() + '</f>');
//remove the inlineStr
$('is', this).remove();
}
})
});
}
}]
});
});