Problem running basic example of SheetJS - error on "return(<>...)

Viewed 13

I try to run the sheetjs example at https://docs.sheetjs.com/docs/

So here's my simple html (I've downloaed the js library in the same folder of my local disk. I run the page from this local folder, not a webserver:

<html>
<body>
<button id="sheetjsexport"><b>Export as XLSX</b></button>
<script src="xlsx.full.min.js"></script>
<script>
document.getElementById("sheetjsexport").addEventListener('click', function() {
  /* Create worksheet from HTML DOM TABLE */
  var wb = XLSX.utils.table_to_book(document.getElementById("TableToExport"));
  /* Export to file (start a download) */
  XLSX.writeFile(wb, "SheetJSTable.xlsx");
});

function Table2XLSX(props) {

  /* Callback invoked when the button is clicked */
  const xport = React.useCallback(async () => {
    /* Create worksheet from HTML DOM TABLE */
    const table = document.getElementById("Table2XLSX");
    const wb = XLSX.utils.table_to_book(table);

    /* Export to file (start a download) */
    XLSX.writeFile(wb, "SheetJSTable.xlsx");
  });

  return (<>
    <table id="Table2XLSX"><tbody>
      <tr><td colSpan="3">SheetJS Table Export</td></tr>
      <tr><td>Author</td><td>ID</td><td>你好!</td></tr>
      <tr><td>SheetJS</td><td>7262</td><td>வணக்கம்!</td></tr>
      <tr><td colSpan="3">
        <a href="//sheetjs.com">Powered by SheetJS</a>
      </td></tr>
    </tbody></table>
    <button onClick={xport}><b>Export XLSX!</b></button>
  </>);
}
</script>

</body>

But, obviously, I've this error in chrome dev tools:

Uncaught SyntaxError: Unexpected token '<' (at test.html:25:11)

What am I missing ? I suppose it's because I do not run this page from webserver but I'm not sure.

I've tried to add reactJS dependencies but it changes nothing:

<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>

Is it possible in "pure" html/javascript (running from filesystem only) ?

0 Answers
Related