본문 바로가기
front/js

javascript xlsx 엑셀 업로드 방법

by juniKang 2022. 6. 17.

npm install --save https://cdn.sheetjs.com/xlsx-0.18.9/xlsx-0.18.9.tgz

import { read } from 'xlsx';
async function upload(e) {
  const file = e.target.files[0];
  const data = await file.arrayBuffer();
  const workbook = read(data);
}

---vue3 사용---

<script setup>
import { read, utils } from 'xlsx';

async function fileToJson(e) {
  const file = e.target.files[0];
  const blob = await file.arrayBuffer();
  const workbook = read(blob);
  const worksheet = workbook.Sheets[workbook.SheetNames[0]];
  return utils.sheet_to_json(worksheet);
}

async function parseData(e) {
  const json = await fileToJson(e);
  console.log(json);
}
</script>
<template>
  <div>
    <input
      class="form-control form-control-sm"
      type="file"
      @change="parseData"
      ref="fileupload"
    />
  </div>
</template>

'front > js' 카테고리의 다른 글

[javascript] falsy  (0) 2022.07.26
[에러]TypeScript language service died unexpectedly 5 times in the last 5 minutes  (0) 2022.07.23
자바스크립트 클로져(Closures )  (0) 2022.06.30
Functions  (0) 2022.05.30
Using Promises  (0) 2022.05.29

댓글