I want to use SheetJS to display an Excel sheet in a small app I am working on. Currently, the Excel workbook is on my local machine, and I want to read the file using SheetJS, then use SheetJS’s sheet_to_html
functionality to display the sheet in the browser.
SheetJS provides a readFile
function, but this does not work on the browser side. They offer a read
file too, which accepts a binary blob of data. I am pretty new to Javascript, and can’t seem to get my local file path as a string into the correct format to be read by SheetJS read
.
Here’s what I want:
const file = "my_local_excel_file.xlsx";
const reader = new FileReader();
data = // ... read file into a binary array buffer from reader
wb = XLSX.read(data);
// get sheet, display as HTML
I’ve been through all the documentation and previous StackOverflow questions, but I can’t seem to find an answer to this question. Nearly all other examples have some File
type which is already a Blob
to be read by XLSX.read
, such as from an upload button. However, my file is coming directly as a string.
I do have a Python backend, and I have tried to parse the data using pandas
and passing the data as JSON to SheetJS, but while that displays something in the browser, the formatting is all wrong.
Does anyone have any advice?