linways/table-to-excel

Percentage Values

coxlr opened this issue · 1 comments

coxlr commented

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

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