admin管理员组

文章数量:1390756

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 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 pleatley automated (with the exception of uploading the xslx file that just a copy and paste thing)

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 pleatley automated (with the exception of uploading the xslx file that just a copy and paste thing)

Share Improve this question edited Jan 23, 2018 at 6:42 Krunal Sonparate 1,14210 silver badges31 bronze badges asked Dec 11, 2016 at 23:29 skyzzleskyzzle 1871 gold badge4 silver badges17 bronze badges 1
  • 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 Commented Dec 11, 2016 at 23:44
Add a ment  | 

2 Answers 2

Reset to default 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.

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./SheetJS/sheetjs
https://developer.mozilla/en-US/docs/Web/API/FileReader

本文标签: excelHow to read an xlsx file with javascriptStack Overflow