Reading local excel file in browser with read-excel-file.js - javascript

I'm trying to create an html table that is based on data coming in from an excel sheet. I plan on using a javascript script to convert the excel data into an html table using read-excel-data.js. I have the excel sheet locally, but am not sure how to send the excel file with the html/js/css to the browser. So in my javascript file when I try to call readXlsxFile("data.xlsx"), data.xlsx is not found because it does not exist within the browser. Is there a way for me to send data.xlsx to the browser without having to manually upload with an input type="file" element?

For obvious security reasons, the browser should not allow this at all except in the case of a user action, such as file input. In fact, think what implications it would have if a Web site could explore and read/write data from the file system on which it is running.
You can only directly receive files from agents such as web servers or similar applications via functions such as fetch(...)

Related

How can I read a local file with a fixed path in Javascript? I only have the location of the file as a string. NO HTML forms allowed

I am creating a web app where I already know the location of a file that needs to be uploaded. Note that all I have is the path (example: Users/username/Downloads or Users/username/Documents) or something like that. How can I get Javascript to read that file as a File object or as a binary string so that I can POST it to a server.
Additionally, this file is not a simple file like a JSON or a txt file. This file would usually be a Microsoft Word file.
Due to security reasons, JavaScript executed from web apps have very limited access to the file system.
The best you can do is have the user select a file via a file input.
If having the web app user install a browser extension is acceptable, a browser extension may have more access to the user's file system. Here is an example extension that accesses a user's file system more directly: https://github.com/buggyj/savetiddlers
I think you can't to read the any files from the front-end by javascript, It is not allowed to do so. But you can get the file path from front-end and then pass it to the app framwork or back-end to processing. Beacuse the app's framework or back-end has the ability to access system files. Whereafter, you can POST to the contents of the file to the web server.

How can you access data in an Excel Spreadsheet using javascript

I have a website that uses some JavaScript to access data in a .xlsx file from a Microsoft Excel Spreadsheet. When testing I was able to access it by having the file in the same folder, however in practice my company uses SquareSpace, and the way to access their files is more complicated than I would like, since I need to set it up so that the less tech savvy people in the company can reupload and update the spreadsheet. Preferably, I'd like to have it so that my script is accessing the file directly from OneDrive. I know it's possible to display a spreadsheet on from OneDrive on SquareSpace (or any website) by embedding it. But I don't need to display the spreadsheet, I need my code to read the data in the spreadsheet and respond to it. Essentially, is there a way to connect a website to a Microsoft Excel document and save the data as JavaScript variables?

Is it possible to save an excel file in local storage and manipulate its data using Javascript?

I am working on a web plateforme that displays different statistics from an excel file in the server.
For a better performance, I want to download the excel file into local storage so the browser does not have to call the server for each action performed by the user.
The file size varies between 200Ko and 2Mo.
Is there an easy way to do that.
Thanks.

How can I get the current Excel file in Office JavaScript API?

I am developing a tab pane app in Excel which needs to read the current document. In Word, the Office JavaScript API has the method Office.context.document.getFileAsync(), but this is not available in Excel.
I can get the URL of the document with Office.context.document.getFileProperties(), and then I thought I could read the file with this.
I tried using the HTML5 FileReader() object, but this only works for files selected from the file input control. I tried manipulating a hidden file input control so it automatically uses the current document, but JavaScript understandably prevents you from doing this for security reasons. I could ask the user to browse to the document they are currently using but that would be a poor user experience.
So I tried using ActiveXObject('Scripting.FileSystemObject') but ActiveX is not allowed in tab pane apps at all, whatever the current security setting are in IE.
What other options do I have?
According to the API road map, Office.context.document.getFileAsync() is not available in Excel at this moment.
I don't think it's feasible by using getFilePropertiesAsync(). It only returns the URL. Usually browser forbids developer touching any content in the file system. Therefore, it's hard to access the local file system in JavaScript code.
Besides, the file may not be in local file system. For example, it could be hosted in Onedrive or SharePoint. getFilePropertiesAsync() should return its real URL in Onedrive/SharePoint, instead of local file system.
I guess Microsoft will support getFileAsync() in the future.

how to open csv file in IE in by javascript

In my asp page, I have to open a csv file in IE by java script. The code which I am using is as below:
csvWindow = window.open("/com/csv/"+csvFileName, "datacsv", "toolbar=yes,location=no,directories=yes,status=no,menubar=yes,scrollbars=yes,resizable=yes,width=790,height=450,screenX=50,screenY=25,left=50,top=25");
Code is running in IIS server.
When I run this code and open csv file it gives below message
Microsoft Office Excel cannot access the file
"http://192.168.3.228:107/com/csv/CSV_file_1345728.csv". There are several possible reasons:
The file name or path does not exist
the file is being used by another program
the workbook you are trying yo save has the same name as a currently open workbook.
But file is being created.So path is correct and i think that file is also not used by another program
Please help me what should I do
The problem is that when Excel is opened it will attempt to fetch the CSV file itself, this a change in behaviour in office apps since 2007. However since Excel runs in a different process it will not send any cookies that would have been generated during the logon. When the website receives the request it will respond with a 401 status.
There are no easy solutions that I know of with entirely satisfactory results. Here are a number of solutions but all have drawbacks.
Make the authentication cookie persistent, this will allow Offices apps to pick up and send the cookie. The down side being the user remains persistently logged even after a client machine reboot (much like how Stackoverflow appears to work).
Use a standard HTTP authentication protocol like "Basic" or "Negotiate". The down side is that this will cause Excel to display a logon box and the user has to logon again. One exception to this drawback is using "Negotiate" or "NTLM" against an IIS box where the site is registered as part of the IE's Intranet Zone, in which case the HTTP stack used by excel will attempt to use the current user credentials.
Have a server side script that can run anonymously send the csv file and include in the URL some unique ID (such as GUID) which is a one off grant of access. Much more complex to set up.
If you want to open the file with MS Excel, you could try not to serve the file directly, but write an ASP page with Content-Type=application/force-download, the real file name ending with .css and the actual file content. In this case, MSIE will first download the file to the local disk cache and then will feed it to MS Excel.
If you just want to show the CSV text in the browser window, maybe the best is to change its extension or to make some proxy page with Content-Type=text/plain and no mention of CSV at all. The association CSV/Excel seems to be hardcoded in MSIE.

Categories

Resources