Fetch Excel files and convert to JSON with SheetJS

artydev - Jul 26 '23 - - Dev Community
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script lang="javascript" src="https://cdn.sheetjs.com/xlsx-0.20.0/package/dist/xlsx.full.min.js"></script>
    <title>Document</title>
</head>
<body>
    <script src="fetchdata.js"></script>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

fetchdata.js

async function FetchExcelData(url) {
  const resp = await fetch(url);
  const bytes = await resp.arrayBuffer();
  const workbook = XLSX.read(new Uint8Array(bytes), {
    type: "array",
  });
  const first_sheet_name = workbook.SheetNames[0];
  const worksheet = workbook.Sheets[first_sheet_name];
  const data = XLSX.utils.sheet_to_json(worksheet, {
    raw: true,
  });
  console.log(data);
}

FetchExcelData("contacts.xlsx");


Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player