My current challenge involves trying to extract a quiz template from an xlsx file in order to create the quiz within it.
Unfortunately, storing the xlsx file as json in a database is not a feasible solution for me at this time.
I experimented with using the xlsx library to directly read the file located in the public directory, but encountered difficulties as the path to the file could not be found. Upon investigating further, I discovered that most browsers do not allow reading files in this manner due to security concerns.
Is there a way to access xlsx files stored directly in the public directory?
This is what my attempt looked like :
handleFile() {
const workbook = XLSX.readFile('/xlsx/quiztemplate.xlsx')
const firstSheetName = workbook.SheetNames[0]
const worksheet = workbook.Sheets[firstSheetName]
const excelData = XLSX.utils.sheet_to_json(worksheet)
console.log(excelData)
}
However, I encountered the following error :
Uncaught Error: Cannot access file /quiz/quiztemplate.xlsx
Despite double-checking the file path multiple times, I am confident that it is not the issue. While the documentation mentions browser restrictions on this functionality, I am uncertain if that is the root cause because the function still attempts to read the file.