linways / table-to-excel

Javascript library to create "valid" excel file from html table with styles
MIT License
224 stars 108 forks source link

Nested Table Support #21

Closed diesburgm closed 5 years ago

diesburgm commented 5 years ago

Added support for tables within table cells and added polyfill for IE support.

Tables within cells will get converted to text using the | character between cells as:

| cell A | cell B | cell C | | cell 1 | cell 2 | cell 3 |

rohithb commented 5 years ago

Please add tests for nested tables so that I can understand how this feature works. Also, all the existing tests are failing, it means all existing features are broken. So make sure none of the existing features is broken.

diesburgm commented 5 years ago

For the life of me I cannot figure out why table.rows is returning undefined when running the unit tests. I verified that jsdom does support this and even upgraded to the latest version. This still seem like the cleanest solution for getting only the top level rows in the table and works on all supported browsers.

Unless you have an idea why table.rows returns undefined when running the Mocha unit tests you can ignore this pull request until I have more time to dig into why this is failing.

rohithb commented 5 years ago

I was not using jsdom properly, that's why table.rows returns undefined. I pushed a fix to it. I saw your solution for handling nested tables and it works okay. But there is no practical use for pipe (|) separated values in an excel cell. I wanted to implement nested tables by properly merging the tables.

diesburgm commented 5 years ago

Thanks for looking at the table.rows. I understand your wanting to nest by merging. This could get quite complex as I have seen some of our reports having pasted html from a single field that has several tables nested within within each other within the cell. Our current use case is to export reports, which may have html pasted into one or more of the table cells, to excel for creating pivot tables or charts on the data. When you add the merging of tables in cells, you could possibly add an option as to how tables within cells should be processed?