3

So I have been googling and googling and googling this for the past few hours and every thing I have tried dose not work.

all I want to do is read the values in the cells (using the field name and index number) of an excel spreadsheet using javascript and then display the data that is in the cells as strings on an webpage.

evey time i google this it eyther sends me to here http://codetheory.in/parse-read-excel-files-xls-xlsx-javascript which I can't get to work and I do not think it is what I want anyway as it looks like its just creating other files to use.

or it takes me to other posts here on stack overflow that either do not answer my question (for example they have converters where you drag and drop an xlsx file in to an converter to convert it to CSV or JSON which will not work because it has to be automated) or they have links that link to other posts that lead me to something that was irreverent.

EDIT----- To make it clear I am only to build a webpage that displays the content that is in the xslx. The xslx file will be replaced every day.

I have no control over what goes on the server other then what is in the folder that holds the webpage and xslx file.

the process has to be compleatley automated (with the exception of uploading the xslx file that just a copy and paste thing)

Krunal Sonparate
  • 1,122
  • 10
  • 29
skyzzle
  • 167
  • 1
  • 4
  • 16
  • 1
    The library mentioned will work fine if file is on server. If it is local you can't access it from browser anyway – charlietfl Dec 11 '16 at 23:44

2 Answers2

1

Excel has no API that JavaScript can access client-side. To the contrary, using VBA you can extract data from the spreadsheet and then open a web browser and write JavaScript into the document that the browser is showing.

To do what you want, you'd need to access the Excel data on the server, via some server-side API (probably .NET) and then deliver that data to the client as HTML, CSS and JavaScript.

FYI: That example you referenced is a server-side solution using node.

Scott Marcus
  • 64,069
  • 6
  • 49
  • 71
  • Cant be server side. I am unable to touch that at all. I have to make an javascript file to read the context of the xlsx file and display it in an html page. that it. just a single folder with every thing in it running that will be copped over to the server. every day the xslx file will be changed. the clients will load the webpage. that it. no instilling anything just copying over files. – skyzzle Dec 11 '16 at 23:44
  • What you are trying to do is not going to be possible. Now, if the Excel file were to be exported to a text-based file (like a .csv) you could make an AJAX call for that data and consume it, But not an .xslx. See: this for details: http://stackoverflow.com/questions/6382572/how-to-read-an-excel-file-contents-on-client-side – Scott Marcus Dec 12 '16 at 00:04
1

You should look at the answers there: How to read an excel file contents on client side?

There is a working solution making use of the SheetJS lib and the FileReader API from javascript.

To read an Excel File this way first you need to read that file as a binary string using the FileReader API then you'll read that binary string using the SheetJS functionnalities.

This can be done 100% client side doesn't involve writing another file or uploading the file on a server, and as it is standard javascript it should works everywhere as long as the web navigator supports the FileReader API.

Related links:
https://github.com/SheetJS/sheetjs
https://developer.mozilla.org/en-US/docs/Web/API/FileReader

Darkosphere
  • 107
  • 8