linways / table-to-excel

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

Cannot set property 'width' of undefined #35

Closed lynx12345 closed 4 years ago

lynx12345 commented 4 years ago

Hi!

I'm implemted succesfully an app with table to excel export, with this approach:

TableToExcel.convert(document.getElementById("table_SP_HOME_VER_PARTE_LOGIS_227"));

in the attach file, that line works fine with table2.html, but when I want to implement a new table (table1.html) it fails with this error:

TableToExcel.convert(document.getElementById("table_SP_GRD_RENDICION_228"))
tableToExcel.js:2 Uncaught TypeError: Cannot set property 'width' of undefined
    at tableToExcel.js:2
    at Array.forEach (<anonymous>)
    at Object.parseDomToTable (tableToExcel.js:2)
    at Object.tableToSheet (tableToExcel.js:508)
    at Object.tableToBook (tableToExcel.js:508)
    at Object.convert (tableToExcel.js:508)
    at <anonymous>:1:14

I don't understand why...

thnks in advance!

examples.zip

rohithb commented 4 years ago

This is because, you defined width for 7 columns (data-cols-width="20,20,15,20,15,15,15") , while your table only contains 4. Just update data-cols-width="20,20,15,20" then it will work. refer #13 also. I will add a fix for this too as @AswinSreenath in #10 .

lynx12345 commented 4 years ago

OK! thnks...