Read Data From Excel

Your code is outside of the oReq.onload function.

Move your code so that it is inside that function.

Or if you prefer, move the closing brace down below your code, so that it separates your code from the send command.

it is insdie

<!DOCTYPE html>
<Html>
<Head>
<script lang="javascript" src="dist/xlsx.core.min.js"></script>
</head>

<body>

<script>
/* set up XMLHttpRequest */
var url = "test_files/formula_stress_test_ajax.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 first_sheet_name = workbook.SheetNames[0];
var address_of_cell = 'A1';

/* 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);
  document.body.innerHTML = "first_sheet_name";

oReq.send();




</script>


</body>


</html>

No it is not. Do you see the closing brace just above the DO SOMETHING comment? That closing brace shouldn’t be there.

That closing brace need to be moved down below your code, so that it separates your code from the send command.

Right>?

<!DOCTYPE html>
<Html>
<Head>
<script lang="javascript" src="dist/xlsx.core.min.js"></script>
</head>

<body>

<script>
/* set up XMLHttpRequest */
var url = "test_files/formula_stress_test_ajax.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 first_sheet_name = workbook.SheetNames[0];
var address_of_cell = 'A1';

/* 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);
  document.body.innerHTML = "first_sheet_name";
}
oReq.send();




</script>


</body>


</html>

That’s better.

Another problem you are likely to face is that using ajax to fetch a local file is not likely to work. The solution to that is to place the excel file (and the other files) on a server somewhere, so that an http request will be used to retrieve the file in the url.

Any idea how to do that?

That’s a task that’s beyond the scope of what we’re dealing with here.

Chrome does let you to allow cross-origin requests, using the Allow-Control-Allow-Origin: * extension.

Is that the browser you are using?

I am using chrome and i just added that extension

Actually, I don’t think that extension will be of any use for accessing local files.

What has worked is to close Chrome, then start is using the following command:
chrome --allow-file-access-from-files

Running the test page results in the excel file being loaded, and demonstrates that it will work properly when on a proper web server too.

Where do i enter this command?

Close Chrome completely, and enter that command from the Run dialog box.

For instructions on how to access the run dialog box, see this article on accessing the run dialog box

Works but it’s display the (document.body.innerHTML = “workbook”:wink:
Workbook. WOrkbook is not in cell a1.

It looks like you will need to use the desired_value variable instead, eh?

It ia displaying “desired_value” now. Stll not displaying a1

Did you mistakenly put it in string quotes?

<!DOCTYPE html>
<Html>
<Head>
<script lang="javascript" src="dist/xlsx.core.min.js"></script>
</head>

<body>

<script>
/* set up XMLHttpRequest */
var url = "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 first_sheet_name = workbook.SheetNames[0];
var address_of_cell = 'A1';

/* 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);
  document.body.innerHTML = "desired_value";
}
oReq.send();




</script>


</body>


</html>

Yes, it certainly looks as if you did place the desired_value variable inside of string quotes.
Get rid of the string quotes.

Page is blank

<!DOCTYPE html>
<Html>
<Head>
<script lang="javascript" src="dist/xlsx.core.min.js"></script>
</head>

<body>

<script>
/* set up XMLHttpRequest */
var url = "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 first_sheet_name = workbook.SheetNames[0];
var address_of_cell = 'A1';

/* 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);
  document.body.innerHTML = "";
}
oReq.send();




</script>


</body>


</html>