Home » Php » php – Exporting HTML Table to xlsx causes INVALID_CHARACTER_ERR

php – Exporting HTML Table to xlsx causes INVALID_CHARACTER_ERR

Posted by: admin February 25, 2020 Leave a comment

Questions:

I am getting the error Uncaught INVALID_CHARACTER_ERR: DOM Exception 5 when I am trying to export html table to excel file. I have used following scripts for converting the table to pdf,csv,xlsx,jpg etc.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"/>
<script type="text/javascript" src="tableExport.js"></script>
<script type="text/javascript" src="jquery.base64.js"></script>
<script type="text/javascript" src="html2canvas.js"></script>
<script type="text/javascript" src="jspdf/libs/sprintf.js"></script>
<script type="text/javascript" src="jspdf/jspdf.js"></script>
<script type="text/javascript" src="jspdf/libs/base64.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

I have created a dropdown menu for this as below:

<div class="dropdown">
  <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
     <span class="glyphicon glyphicon-th-list"></span> Dropdown

  </button>
  <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
    <li><a href="#" onclick="$('#sheettable').tableExport({type:'json',escape:'false'});"> <img src="images/json.jpg" width="24px"> JSON</a></li>
                                <li><a href="#" onclick="$('#sheettable').tableExport({type:'xml',escape:'false'});"> <img src="images/xml.png" width="24px"> XML</a></li>
                                <li><a href="#" onclick="$('#sheettable').tableExport({type:'sql'});"> <img src="images/sql.png" width="24px"> SQL</a></li><li><a href="#" onclick="$('#sheettable').tableExport({type:'excel',escape:'false'});"> <img src="images/xls.png" width="24px"> XLS</a></li>
                                <li><a href="#" onclick="$('#sheettable').tableExport({type:'doc',escape:'false'});"> <img src="images/word.png" width="24px"> Word</a></li>

  </ul>
</div>

I have used tableExport.js file for the same. But getting the error:

Uncaught INVALID_CHARACTER_ERR: DOM Exception 5
How to&Answers: