tableExport.jquery.plugin
tableExport.jquery.plugin copied to clipboard
Multiple lines
In function parseString there is: `var text = htmlData.replace(/\n/g,'\u2028').replace(/<br\s*[/]?>/gi, '\u2060'); var obj = $('
').html(text).contents(); text = ''; $.each(obj.text().split("\u2028"), function(i, v) {
if (i > 0)
text += " ";
text += $.trim(v);
});
$.each(text.split("\u2060"), function(i, v) {
if (i > 0)
result += "\n";
result += $.trim(v).replace(/\u00AD/g, ""); // remove soft hyphens
});`
Isn't that error? There shouldn't be: text += "\n" ? Because for now you can't export text with multiple lines (separated by character: \n) for example to csv. Current code replace \n with \u2028, split text by this and join with space instead of new line character
I don't think that this is an error. Let me show why by an example: The following html code
<table>
<thead>
<tr>
<th>column 1</th>
<th>column 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>A</td>
<td>
Line 1<br>
Line 2<br>
Line 3
</td>
</tr>
<tr>
<td>B</td>
<td>
Line 1
Line 2
Line 3
</td>
</tr>
<tr>
<td>C</td>
<td> </td>
</tr>
</tbody>
</table>
will be rendered by the browser to this:
As you can see multiple lines, separated by a newline character, will be concatenated into one line. Where as multiple lines, separated by a <br>
tag will be wraped. This behavior should also be achieved by the parseString function. Thus when you export the example to excel you will get this:
I hope this answers your question. Thanks.
Hey @hhurz ,
I am trying to accomplish this multiple lines cells export representation.. But it seems my <br>
tags are not converted to the new lines..
HTML:
<td>
AAA<br>
BBB<br>
CCC
</td>
This is exported into CSV as "AAABBBCCC"....
CSV Export settings:
elm.tableExport({
type: 'csv',
escape: false,
ignoreColumn: colIgnore,
maxNestedTables: 2,
preserve : {
leadingWS: true,
trailingWS: true
},
csvUseBOM: (d?d.csvUseBOM:false),
fileName: (s?s:'TableExport') + formattedDate()
});
I would either try to accomplish this:
Or write a function to convert <br>
into ", ".. So instead of "AAABBBCCC" I would have in cell "AAA, BBB, CCC". That could be a new feature where you would define a delimiter in case multiline cells..
Thanks again, Michal
Hi, thanks for reporting this issue. It's a regression bug and will be fixed in next release. Normal behavior should be that new lines will be turned into spaces and <b>
tags into new lines, as I described it above in 2016
How would new lines work for csv? Or for json/xml?
Working fine. For my understanding new lines do not violate the specs of those formats. When opening such a csv file in Excel you get the result as you would acomplish it (see above). The json result was accepted by online validators and could successfully open it in my json viewer. Same for xml.
Thx again, waiting for the update :)
Updated to 1.9.15 and bug still present.. Both scenarios (new lines or <br>
) result into merged oneliner..
Not for me:
Ok, got it: The detection of br tags containing attributes doesn't work. That needs to be fixed... ...Done. See v1.9.16, thanks
Hey, tested and wokrs!
However I came to point out configuration where I have <div></div>
within cell to devide content to the new lines.. This does not work and is exported as single continuous line :/
I would like to clarify here what is the recommended way to split content into multiple lines within cell not using angular and your library will respect it?
Other question here what about the proposed attribute for separator in case of new lines? So by default it would be \n
, and it can be configured to any valid string ,
, or |
, or :
.. etc - this would be nice feature to have :)
I think you could solve this by using one of the provided callback functions onCellHtmlData or onCellData. Both are called during parsing of every cell. onCellHtmlData is called at the beginning and onCellData at the end of the parse process. Look in the clossed issues (e.g #44) for onCellHtmlData to get more information.
Regarding the proposed attribute: I put this on to my feature request list...
Hi! I'm trying to display multiple lines with an xlsx format. Any suggestions?
@jwiel86 What have you tried until now?
In my case <br/>
works. But <br>
does not.