🖥

Nuxt3 - SheetJs で JSON をエクセルファイルに変換してダウンロードする

2024/03/09に公開

インストール

npm i --save https://cdn.sheetjs.com/xlsx-0.20.1/xlsx-0.20.1.tgz

参考:

https://docs.sheetjs.com/docs/

コード例

<script setup>
import { ref } from 'vue'
import { utils, writeFileXLSX } from 'xlsx'

const pres = ref([
  { name: 'George Washington', birthday: '1732-02-22' },
  { name: 'John Adams', birthday: '1735-10-19' },
])

function exportFile() {
  const ws = utils.json_to_sheet(pres.value)
  const wb = utils.book_new()
  utils.book_append_sheet(wb, ws, 'Data')
  writeFileXLSX(wb, 'SheetJSVueAoO.xlsx')
}
</script>

<template>
  <button @click="exportFile">Export XLSX</button>
</template>

動作例

参考

https://docs.sheetjs.com/docs/getting-started/examples/export/

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

プロフィール・経歴

https://github.com/YumaInaura/YumaInaura

公開日時

2024-02-29

GitHubで編集を提案

Discussion