【JS导出Excel】Excel解决乱码问题、电话身份证显示为科学计数法问题

时间:2021-03-21 00:39:00

1、乱码

统一编码即可:

<meta charset="UTF-8">

template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><meta charset="UTF-8"><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>';

2、科学计数法

style中添加样式mso-number-format:'\@';  其他样式可以百度

<td align="center" style="width:200px;mso-number-format:'\@';" >
  <div style="" title="${ po.userTel } ">${ po.userTel }</div>
</td>