linways / table-to-excel

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

Percentage Values #24

Closed coxlr closed 5 years ago

coxlr commented 5 years ago

Is it possible to use percentage values where you are including the % symbol in the html?

If i use a % symbol and then try to set the cell as data-t="n" is caused the cell to display "NaN" If I do not add data-t="n" excel treats the cell as a text field.

Here is a code pen showing the problem I am currently experiencing

https://codepen.io/coxy121/pen/KKPNPoa

rohithb commented 5 years ago

A workaround for this problem is

Using a hidden column for exporting percentage to excel.

   <tr>
      <td>
        Some percentage
      </td>
      <td data-exclude="true">
        23%
      </td>
      <td class="hidden"
          data-t="n"
          data-num-fmt="00.0%">
        0.253
      </td>
    </tr>

In the above example, 2nd td will be displayed and 3rd td will be hidden on the browser and the opposite in the exported excel. The exported excel will recognise the value as percentage.

Otherwise, you have to use data-t as string(which is the default value for data-t).