function importExcel() {
sAlert("importExcel");
var fileDialog = $('<input type="file">');
fileDialog.click();
fileDialog.on("change", onFileSelected);
return false;
};
var onFileSelected = function (e) {
//var filePath = $(this).val();
if (this.files.length > 0) {
var file = this.files[0];
var reader = new FileReader();
sAlert("file " + file.name);
}
reader.onload = function (e) {
sAlert("reader.onload ");
var data = new Uint8Array(e.target.result);
sAlert("data " + data);
//const XLSX = xlsx;
//var workbook = XLSX.read(data, { type: 'array' });
var XLSX = require("xlsx");
var workbook = XLSX.read(data, { type: 'array' });
sAlert("workbook " + workbook.name);
var formulario = workbook.SheetNames['Formulario'];
sAlert("worksheet " + formulario.name);
var worksheet = wb.Sheets[formulario];
//var worksheet = workbook.Sheets[workbook.SheetNames['Formulario']];
sAlert("worksheet " + worksheet.name);
// Agora você pode trabalhar com os dados da planilha
var jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1 });
sAlert(jsonData);
//console.log(jsonData);
// Exemplo de como acessar uma célula específica
var cellValue = worksheet['A1'].v;
sAlert(cellValue);
//console.log(cellValue);
};
sAlert("readAsArrayBuffer " + file.name);
reader.readAsArrayBuffer(file);
//sAlert($(this)[0].files);
};
我想包括XLSX.read库,但我不知道如何,有人可以帮助我吗?
1条答案
按热度按时间m528fe3b1#
你可以从github下载:https://github.com/SheetJS/sheetjs
之后包括在您的项目中
Chnage src地址与您的。
使用方法如下: