Please, is it possible to read documents like excel sheets, notepad etc into JavaScript and use the data in the document for computations. Please, if it is possible, I would love to know how to do it. Thank you
-
You can use AJAX requests to load files from the same domain/port as your website, and parse them according to their file schemes. There are libraries or APIs for most interesting file formats, for instance the JavaScript API for office is discussed here: msdn.microsoft.com/en-us/magazine/jj891051.aspxJacob Brazeal– Jacob Brazeal2016-05-21 19:12:04 +00:00Commented May 21, 2016 at 19:12
-
on a web page? for example using an upload button/ptvty– ptvty2016-05-21 19:13:00 +00:00Commented May 21, 2016 at 19:13
-
You can use excel sheets as data source files as long as you save them in csv format. Without any problems. If your aim is to build a desktop html application - targeting Explorer, you can make use of FileSystemObject to. Search with: google.com/#q=msdn+filesystemobject+excel+JScriptBekim Bacaj– Bekim Bacaj2016-05-21 19:30:12 +00:00Commented May 21, 2016 at 19:30
-
@chika please consider marking the answer if it helped you, otherwise leave a comment if you need further info.ptvty– ptvty2016-06-08 09:40:34 +00:00Commented Jun 8, 2016 at 9:40
Add a comment
|
1 Answer
You can access the selected file without uploading it, but you'll need the HTML5 file API:
function readSingleFile(evt) {
//Retrieve the first (and only!) File from the FileList object
var f = evt.target.files[0];
if (f) {
var r = new FileReader();
r.onload = function(e) {
var contents = e.target.result;
alert(contents);
}
r.readAsText(f);
} else {
alert("Failed to load file");
}
}
document.getElementById('fileinput').addEventListener('change', readSingleFile, false);
Check this fiddle out:
Just select a txt file https://jsfiddle.net/n454do1d/1/
1 Comment
chika
It really helped me...thank you...sorry for replying this late