Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple lines #124

Open
kamparR opened this issue Nov 16, 2016 · 15 comments
Open

Multiple lines #124

kamparR opened this issue Nov 16, 2016 · 15 comments

Comments

@kamparR
Copy link

kamparR commented Nov 16, 2016

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

@hhurz
Copy link
Owner

hhurz commented Nov 17, 2016

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 hhurz added the Q&A label Nov 17, 2016
@hhurz hhurz closed this as completed Dec 2, 2016
@aronmgv
Copy link

aronmgv commented Aug 23, 2018

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

hhurz pushed a commit that referenced this issue Aug 23, 2018
@hhurz
Copy link
Owner

hhurz commented Aug 23, 2018

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

@aronmgv
Copy link

aronmgv commented Aug 23, 2018

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

@hhurz
Copy link
Owner

hhurz commented Aug 24, 2018

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.

@aronmgv
Copy link

aronmgv commented Aug 26, 2018

Thx again, waiting for the update :)

@aronmgv
Copy link

aronmgv commented Aug 28, 2018

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

@hhurz
Copy link
Owner

hhurz commented Aug 28, 2018

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

issue124

@aronmgv
Copy link

aronmgv commented Aug 30, 2018

Not for me:

image

image

image

image

image

@hhurz
Copy link
Owner

hhurz commented Aug 30, 2018

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

@aronmgv
Copy link

aronmgv commented Aug 31, 2018

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

@hhurz
Copy link
Owner

hhurz commented Sep 3, 2018

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 hhurz reopened this Sep 3, 2018
@jwiel86
Copy link

jwiel86 commented Oct 22, 2018

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

@hhurz
Copy link
Owner

hhurz commented Oct 23, 2018

@jwiel86 What have you tried until now?

@smrrrazu
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants