html2csv icon indicating copy to clipboard operation
html2csv copied to clipboard

Line with empty fields/cells are being skipped

Open greatkemo opened this issue 5 years ago • 2 comments

Hi,

Love this project, it is very handy. I noticed that the tool skips lines of a table that have empty cells in the line. Any way we can remedy that?

In my case, the table I need to consistently convert has and will always have some blank fields and that's ok, will love it if the tool can accept it not skip the line.

Thanks again. Kamal

greatkemo avatar May 03 '20 08:05 greatkemo

What blank do you mean? An empty

cell, or tag is missing?

hanwentao avatar May 12 '20 11:05 hanwentao

Hi,

After doing more digging, it looks like the table I am trying to convert has some cells that do not start with <tr> tag.

For example, we have a table with a list of courses like so:

id     name          section    instructor
101    math            1           John
201    science         1           Mike
                       2           Jill
301    english         1           Tim

The HTML code for that would look like this:

<table>
             <tr>
                     <td>
                          id
                    </td>
                     <td>
                          name
                    </td>
                     <td>
                          section
                    </td>
                     <td>
                          instructor
                    </td>
              </tr>
             <tr>
                     <td>
                          101
                    </td>
                     <td>
                          math
                    </td>
                     <td>
                          1
                    </td>
                     <td>
                          John
                    </td>
              </tr>
             <tr>
                     <td>
                          201
                    </td>
                     <td>
                          science
                    </td>
                     <td>
                          1
                    </td>
                     <td>
                          Mike
                    </td>
              </tr> 
                                     // notice no opening table row tag
                     <td>
                                   // empty cell
                    </td>
                     <td>
                                 // empty cell
                    </td>
                     <td>
                          2
                    </td>
                     <td>
                          Jill
                    </td>
              </tr>        // notice closing table row tag
             <tr>
                     <td>
                          301
                    </td>
                     <td>
                          english
                    </td>
                     <td>
                          1
                    </td>
                     <td>
                          Tim
                    </td>
              </tr>

Notice that the row below science starts with an empty cell which means the same as above. This is because this course has 2 sections, taught by 2 different instructors.

What I noticed is that after Mike the HTML table closes </td></tr> and the next line of the code starts <td> without <tr> then after Jill it is closed again with </td></tr>.

Now I am not sure why the table is designed this way, but I found that this is a common practice on some forums.

In my case, I found that the resulting CSV was missing lines that didn't start with <tr>.

Hope that gives you a better understanding of the issue. I understand this may be a special case, but thought I would bring it to your attention anyway.

Let me know if you need more information.

Best, Kamal

greatkemo avatar May 12 '20 12:05 greatkemo