简体   繁体   English

出现错误:TypeError:无法读取 null 的属性(读取“0”)

[英]Getting Error: TypeError: Cannot read properties of null (reading '0')

I want to upload an excel file for that I used ng-click and define the fileUpload($event) function in the app controller scope and with the help of xlsx I want to read the file in JSON but while running the code getting this error-我想上传一个 Excel 文件,我使用 ng-click 并在应用程序控制器范围内定义 fileUpload($event) 函数,并在 xlsx 的帮助下我想以 JSON 格式读取文件,但在运行代码时出现此错误-

 <div>
     <input id="file-upload" type="file"/>
     <input type="button" value="Upload" ng-click ="fileUpload($event)">
 </div>
   $scope.fileUpload = function(mE) {
        const file = mE.target.files[0];
        const fileReader = new FileReader();
        fileReader.readAsBinaryString(file);
        fileReader.onload = (e) => {
            var workBook = XLSX.read(fileReader.result, {type: 'binary'});
            var sheetNames = workBook.SheetNames;
            var ExcelData = XLSX.utils.sheet_to_json(workBook.Sheets[sheetNames[0]]);
                console.log(ExcelData);
         };
     };
 TypeError: Cannot read properties of null (reading '0')
 at $scope.fileUpload 
 at site.js?ver=1:1:47308
 at t (site.js?ver=1:1:5384)
 at a.$eval (site.js?ver=1:1:4894)
 at a.$apply (site.js?ver=1:1:4119)
 at HTMLInputElement.<anonymous> (site.js?ver=1:1:5035)
 at HTMLInputElement.dispatch (site.js?ver=1:1:200)
 at p.handle (site.js?ver=1:1:40)

Try this in your fileUpload function在你的 fileUpload 函数中试试这个

const file  = document.getElementById('file-upload').files[0];
...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我收到这个“TypeError:无法读取 null 的属性(读取'长度')” - I'm getting this "TypeError: Cannot read properties of null (reading 'length')" 为什么我不断收到此错误? 未捕获的类型错误:无法读取 null 的属性(读取“术语”) - why do i keep getting this error? Uncaught TypeError: Cannot read properties of null (reading 'term') 从 localStorage 获取数据时出现此错误(类型错误:无法读取 null 的属性(读取 &#39;insertRow&#39;)) - Getting this error while fetching data from localStorage(TypeError: Cannot read properties of null (reading 'insertRow')) 在 useState 使用反应中出现错误“TypeError:无法读取 null 的属性(读取‘useState’)” - getting error "TypeError: Cannot read properties of null (reading 'useState')" on useState usage react 错误类型错误:无法读取 null 的属性(读取“toISOString”) - ERROR TypeError: Cannot read properties of null (reading 'toISOString') 在 reactjs TypeError 中出现错误:无法读取未定义的属性(读取“过滤器”) - Getting error in reactjs TypeError: Cannot read properties of undefined (reading 'filter') TypeError:无法读取 null 的属性(读取“_rawValidators”) - TypeError: Cannot read properties of null (reading '_rawValidators') TypeError:无法读取 null 的属性(读取“长度”) - TypeError: Cannot read properties of null (reading 'length') TypeError:无法读取 null 的属性(读取“文档”) - TypeError: Cannot read properties of null (reading 'document') TypeError:无法读取 null 的属性(读取“classList”) - TypeError: Cannot read properties of null (reading 'classList')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM