0

I am trying to fill an array from an Excelsheet. I have tried many attempts but in an other post I had a partial answer.

CSV is a format more portable than XLS which can be exported from excel. 
This format is easy to be parsed (try to export a CSV file from XLS in excel and open it with a text editor by yourself!). 
If this change in format is acceptable, the problem can be simplified quite a lot.

I made .csv and also a .txt folder on my desktop but I am not able to read it. I have tried many html/js code and I have encountered this answer from the console.

testexcel.html:43 Access to XMLHttpRequest at 'file:///C:/exceltest2.1.txt' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.

or with fetch the same

Fetch API cannot load file:///C:/Users/ubi11/Desktop/exceltest2.1.txt. URL scheme must be "http" or "https" for CORS request. getData @ testexcel.html:15 (anonymous) @ testexcel.html:12

I tried to put my file in google drive then:

Access to fetch at 'https://drive.google.com/file/d/1XxRJeH2yOyAmatnhj-zF2CsGz1R3WzQk/view?usp=sharing' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

What is CORS policy? is there a way to read a file and parse what is inside? if there is no solution, can I do what I need through GoogleSheet or will I have the same problem? I actually need to do something easy, read a list of numbers in 4 columns. I don't want to put this list neither in the js code nor in an sql database.
TY

ubi
  • 41
  • 5
  • Can you provide the code that you have tried ? – Moh682 Dec 25 '20 at 00:31
  • Cors is a security policy for browser. Mozilla provides great explanation on its purpose. https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS – Moh682 Dec 25 '20 at 00:33
  • Before you worry too much about the file format like CSV (that's the easy part), you need to understand how to interact with files using a web browser and JavaScript. Please start here and read all of this carefully: https://developer.mozilla.org/en-US/docs/Web/API/File/Using_files_from_web_applications – Randy Casburn Dec 25 '20 at 00:56
  • well it seems very complicated for a newbie to go all through this. there is no solution for such a simple thing. what do you suggest ? going through a server? googlesheet?(i had the same cors problem with google drive) – ubi Dec 28 '20 at 00:57

0 Answers0