tableExport.jquery.plugin icon indicating copy to clipboard operation
tableExport.jquery.plugin copied to clipboard

Multiple lines

Open kamparR opened this issue 8 years ago • 15 comments

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

kamparR avatar Nov 16 '16 07:11 kamparR

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: issue124

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:

issue124_2

I hope this answers your question. Thanks.

hhurz avatar Nov 17 '16 20:11 hhurz

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: image

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

aronmgv avatar Aug 23 '18 14:08 aronmgv

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

hhurz avatar Aug 23 '18 19:08 hhurz

How would new lines work for csv? Or for json/xml?

aronmgv avatar Aug 23 '18 20:08 aronmgv

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.

hhurz avatar Aug 24 '18 19:08 hhurz

Thx again, waiting for the update :)

aronmgv avatar Aug 26 '18 22:08 aronmgv

Updated to 1.9.15 and bug still present.. Both scenarios (new lines or <br>) result into merged oneliner..

aronmgv avatar Aug 28 '18 14:08 aronmgv

Working for me 🤔 Here you see the result when exporting table "issue124" from the testfile as csv:

issue124

hhurz avatar Aug 28 '18 18:08 hhurz

Not for me:

image

image

image

image

image

aronmgv avatar Aug 30 '18 15:08 aronmgv

Ok, got it: The detection of br tags containing attributes doesn't work. That needs to be fixed... ...Done. See v1.9.16, thanks

hhurz avatar Aug 30 '18 16:08 hhurz

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 :/

image

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 :)

aronmgv avatar Aug 31 '18 11:08 aronmgv

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...

hhurz avatar Sep 03 '18 08:09 hhurz

Hi! I'm trying to display multiple lines with an xlsx format. Any suggestions?

jwiel86 avatar Oct 22 '18 18:10 jwiel86

@jwiel86 What have you tried until now?

hhurz avatar Oct 23 '18 11:10 hhurz

In my case <br/> works. But <br> does not.

smrrrazu avatar Jan 16 '19 14:01 smrrrazu