Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/402.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript js xlsx未捕获类型错误:console.log不是函数_Javascript_Excel_Bookmarklet - Fatal编程技术网

Javascript js xlsx未捕获类型错误:console.log不是函数

Javascript js xlsx未捕获类型错误:console.log不是函数,javascript,excel,bookmarklet,Javascript,Excel,Bookmarklet,我正在使用xlsx读取Excel文件。它有点管用。。。至少第一排。我不知道有什么问题,所以我来了 这是我的代码: /* set up XMLHttpRequest */ var url = "http://localhost/test.xlsx"; var oReq = new XMLHttpRequest(); oReq.open("GET", url, true); oReq.responseType = "arraybuffer"; oReq.onload = f

我正在使用xlsx读取Excel文件。它有点管用。。。至少第一排。我不知道有什么问题,所以我来了

这是我的代码:

  /* set up XMLHttpRequest */
  var url = "http://localhost/test.xlsx";
  var oReq = new XMLHttpRequest();
  oReq.open("GET", url, true);
  oReq.responseType = "arraybuffer";

  oReq.onload = function(e) {
    var arraybuffer = oReq.response;

    /* convert data to binary string */
    var data = new Uint8Array(arraybuffer);
    var arr = new Array();
    for(var i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
      var bstr = arr.join("");

    /* Call XLSX */
    var workbook = XLSX.read(bstr, {type:"binary"});

    /* DO SOMETHING WITH workbook HERE */
    var alphabet = "ABC".split("");
    var first_sheet_name = workbook.SheetNames[0];

    /* Get worksheet */
    var worksheet = workbook.Sheets[first_sheet_name];
    var address_of_cell, desired_cell, desired_value;
    var descript;

    for (i=1;i<30;i++) {
      for (j=0;j<alphabet.length;j++) {
        if (alphabet[j] == "A") {
          console.log("This will be title: "+getValue(alphabet[j], i));
        } else if (alphabet[j] == "B") {
          descript = getValue(alphabet[j], i);
          console.log(""+descript);
        } else if (alphabet[j] == "C") {
          console.log="This will be description: " + descript+" - "+getValue(alphabet[j], i);
        }
      }
    }

    function getValue (column, row) {
      address_of_cell = column+''+row;
      console.log(address_of_cell);
      /* Find desired cell */
      desired_cell = worksheet[address_of_cell];
      /* Get the value */
      desired_value = desired_cell.v;
      return(desired_value);
    }
  };
  oReq.send();
正如您在C1中看到的,我知道console.log不是一个功能,但为什么?我的错在哪里?我做错了什么

真诚地,
Thomas

console.log由代码运行的环境提供。或者不是。这取决于环境。现代浏览器提供了它(至少在您打开了devtools的情况下是这样;如果您没有打开,某些版本的IE不会提供)。NodeJS提供了它

两种可能性:

  • 您的环境无法提供它

  • 确实如此,但您运行以下代码行:

    console.log="This will be description: " + descript+" - "+getValue(alphabet[j], i);
    
    它会用一个字符串覆盖它。字符串不是函数,因此在正确使用它的任何行(如
    console.log(单元的地址);
    )上调用它的尝试现在将开始失败

    该行应该与其他行一样,是一个函数调用:


  • 天哪!这对我来说是巨大的失败!哈哈,谢谢你我接受了答案。非常感谢你,很抱歉为这么一件小事耽误了你的时间。
    console.log="This will be description: " + descript+" - "+getValue(alphabet[j], i);
    
    console.log("This will be description: " + descript+" - "+getValue(alphabet[j], i));