Excel export and newlines replaced by a lot of spaces
Excel export and newlines replaced by a lot of spaces
itajackass
Posts: 165Questions: 49Answers: 3
Hi I just create a test case here:
https://live.datatables.net/luzonuli/2/edit
The problem is that during export, the newlines found are replaced with leading spaces. I'd like to export removing these spaces? any solution?
Answers
I suggest that you do some debugging of the format function to see the original data from the cell and the result of the regex statement. One way is with console.log statements like this:
https://live.datatables.net/luzonuli/3/edit
Note that I changed the regex replace line to reassign the result to the
data
variable. The result of the statement doesn't update the variable without reassigning it.The white space you see in the Excel file is found in the table data. You have this for example:
There are leading spaces in the second line (line 9). HTML does not display multiple consecutive spaces to save space on the page which is why they don't show in the table. You will need to remove the consecutive spaces or a better option would be to use a
<br>
in the cell, like this:Note that Excel doesn't use
\r\n
for new lines within the cell. This thread shows how I have handled new lines with Excel.Kevin
Ok i've found this workaround:
https://live.datatables.net/gawusuwe/1/edit