Search code examples
typescriptfilereadersheetjs

SheetJS (js-xlsx) in browser: read a workbook from a Blob


I am running into a wall trying to use SheetJS to build a Workbook object from a Blob, as opposed to a client event like a drag-and-drop or file input element event. The latter two are covered in the documentation's examples but I lack the JS-fu required to translate backward from the Blob that I have, through the FileReader events and into the XLSX.read() API.

Given a Blob in a browser, how can this be accomplished, or can it?


Solution

  • You can do

    var wb = XLSX.read(await blob.arrayBuffer(), { type: "array" });