Line break in Excel export
Line break in Excel export
tombosch
Posts: 2Questions: 1Answers: 0
Hello,
I am searching for a solution to create line breaks in an Excel export. Can someone complete my code to replace the '<br>' in my HTML to a line break in Excel? After hours of searching and trying, my hair is start to fall of ;-)
(This code adds '<br>
' in Excel instead the line break.)
Thank u very much in advance!
My code:
$( document ).ready(function() {
var fixNewLine = {
exportOptions: {
format: {
body: function ( data, column, row ) {
return column === 5 ?
data.replace( /<br\s*\/?>/gi, '"'+"\r\n"+'"' ) :
data;
}
}
}
};
$('#example').DataTable({
dom: 'Bfrtip',
buttons:[
$.extend( true, {}, fixNewLine, {
extend: 'copyHtml5'
} ),
$.extend( true, {}, fixNewLine, {
extend: 'excelHtml5'
} ),
$.extend( true, {}, fixNewLine, {
extend: 'pdfHtml5'
} )
]
});
});
This discussion has been closed.
Answers
me too!
If I remember it correctly, excel only needs a newline ( \n ). At least when used with Windows. For a Mac it's \r\n . So try and change the replacement code with this:
Did you ever get an answer to this? I've been Googling for 5 hours and just can't get an answer. Either it strips all the HTML or if I replace br with \n, I get all of the code with the < replaced with < and still don't get the new line. I really love this tool, and with TableTools, it used to work, but it just quit exporting to Excel and I'm having to go back to the drawing board. And stripNewlines: false doesn't seem to do anything at all.