代码之家  ›  专栏  ›  技术社区  ›  Lee Merlas

将忽略对表所做的更改

  •  0
  • Lee Merlas  · 技术社区  · 5 年前

    sheet_to_html 并设置 editable 事实上,我注意到我所做的改变并没有被持久化。我用了这个函数 table_to_book 为了将HTML数据解析到工作簿中,并且当我将结果记录到控制台时,数据将保留其原始值。

    我的JS和HTML代码,用于获取并以HTML格式显示:

    function fetchData() {
        var req = new XMLHttpRequest();
        req.open('GET', myUrl, true);
        req.responseType = 'arraybuffer';
        
        req.onload = function(event) {
          let arraybuffer = req.response;
          /* convert data to binary string */
          let data = new Uint8Array(arraybuffer);
          let arr = new Array();
          for(let i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
          let bstr = arr.join("");
          
          /* Call XLSX */
          let workbook = XLSX.read(bstr, {type:"binary"});
          console.log(workbook);
          var o = XLSX.utils.sheet_to_html(workbook.Sheets[workbook.SheetNames[0]], {editable:true}).replace("<table", '<table id="data-table" border="1"')
          document.getElementById('data-table').outerHTML = o;
        }
    
        req.send();
      }
      
    function saveFile(){
        var tbl = document.getElementById('data-table');
        var saved_wb = XLSX.utils.table_to_book(tbl);
        console.log(saved_wb);
    }
    <table id="data-table">
    </table>
    
    <input type="submit" value="Fetch" onclick="fetchData()">
    <input type="submit" value="Save" onclick="saveFile()">

    这是sheetJS中已知的错误吗?还是我错过了什么重要的东西?

    0 回复  |  直到 5 年前
    推荐文章