excel - 是否可以读取 Excel 表并纯粹在前端显示其内容?
问题描述
我在想我是否可以使用 XLSX 读取 Excel 表的内容并在前端显示其内容。
我尝试使用读取文件
tmpArray= [];
reader.onload = function(e : any) {
var data = new Uint8Array(e.target.result);
var workbook = XLSX.read(data, {type: 'array'});
let worksheet = workbook.Sheets[workbook.SheetNames[0]];
// sample values //
let desired_cell = worksheet['B5'];
let cellB16 = worksheet['B16'];
// sample values //
let desired_value12 = (cellB16 ? cellB16.v : undefined);
tmpArray.push[desired_value12];
};
but outside this onload function, array of tmpArray don't exist anymore.
So what i wanted is to access the tmpArray and it's contents after the onload function. Is there any work around to do this?
解决方案
请进行以下更改,您将能够tmpArray
从任何地方访问 的值。
tmpArray; // changed here and moved it to outside the function
let self = this; // please note this change
reader.onload = function(e : any) {
var data = new Uint8Array(e.target.result);
var workbook = XLSX.read(data, {type: 'array'});
let worksheet = workbook.Sheets[workbook.SheetNames[0]];
// sample values //
let desired_cell = worksheet['B5'];
let cellB16 = worksheet['B16'];
// sample values //
let desired_value12 = (cellB16 ? cellB16.v : undefined);
self.tmpArray = desired_value12; // changed here
};
推荐阅读
- javascript - Angular在构建时没有嵌入所有脚本
- xml - WPF - Defining a xmlns based on another xmlns
- python - How can I increment numbers in a list without creating a new list?
- azure-storage - 使用共享访问签名的 Azure 文件存储 API 访问
- angular - Angular:自动接受自签名证书
- python - Python:提取与另一个 .txt 中的某个单词匹配的 .txt 的某些行(如 grep 函数)
- tensorflow - 在 GCP Dataproc 上的 Keras 模型上使用分布式 TensorFlow
- c# - 是否可以将控制台窗口(由 AllocConsole 创建)创建为 GUI 子窗口?如果是这样,怎么做?
- java - 无法在控制器中自动装配多个服务
- java - 必须启动 InstrumentationLoadTimeWeaver / openjdk 11