I am trying to read XLSX file one cell data. but I get an error "Uncaught Error: Cannot access file"
Uncaught Error: Cannot access file Hinnapakkumine.xlsx
at V (xlsx.full.min.js:12)
at qv (xlsx.full.min.js:22)
at Object.eg (xlsx.full.min.js:22)
at HTMLButtonElement.document.getElementById.onclick (Javascript.js:28)
My final coal is to replace one cell value to the variable hind and the point of this code is to get contact form data after a button is clicked and edit excel file with that data. Why am I getting this error and how to solve it?
document.getElementById("saatmisnuppKontakt").onclick = function() {
var laius = document.getElementById("laiusKontakt").value;
var pikkus = document.getElementById("pikkusKontakt").value;
var kõrgus = document.getElementById("korgusKontakt").value;
var hind = 0;
if (pikkus * laius >= 100){
hind = pikkus * laius * 85;
}else if (100 < pikkus * laius <= 200 ){
hind = pikkus * laius * 77;
}else if (200 < pikkus * laius <= 1000 ){
hind = pikkus * laius * 75;
}else if (1000 < pikkus * laius <= 2000 ){
hind = pikkus * laius * 80;
}else if (2000 < pikkus * laius <= 4000) {
hind = pikkus * laius * 85;
}
if (3 <= kõrgus <= 6){
hind *= 1;
}else if(kõrgus == 7){
hind *= 1.1;
}else if (kõrgus == 8){
hind *= 1.2;
}else if (kõrgus == 9) {
hind *= 1.3;
}
var workbook = XLSX.readFile('Hinnapakkumine.xlsx');
/* DO SOMETHING WITH workbook HERE */
var first_sheet_name = workbook.SheetNames[0];
var address_of_cell = 'G18';
/* Get worksheet */
var worksheet = workbook.Sheets[first_sheet_name];
/* Find desired cell */
var desired_cell = worksheet[address_of_cell];
/* Get the value */
var desired_value = (desired_cell ? desired_cell.v : undefined);
window.alert(desired_value);
};
Unfortunately you can't use readFile in the browser:
readFile is only available in server environments. Browsers have no API for reading arbitrary files given a path, so another strategy must be used.