Vue ์์ ๋ค์ด๋ก๋
์๋ฒ๋ฅผ ๊ฑฐ์น์ง ์๊ณ ํ๋ฉด ์์์ xlsx ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํด ์์ ๋ค์ด๋ก๋๋ฅผ ํ๋ ๋ฐฉ๋ฒ์ด๋ค.
xlsx ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค์น
npm install --save xlsx
xlsx ๋ฅผ ์ฌ์ฉํ ์์ ๋ค์ด๋ก๋ ๊ธฐ๋ฅ ๊ตฌํ
import xlsx from 'xlsx';
...
excelDownload() {
const fileName = 'excelFile'; // ํ์ผ๋ช
const sheetName = 'sheet1'; // ์ํธ๋ช
const header = [['์ด๋ฆ', '๋์ด', '์ด๋ฉ์ผ']]; // ์ปฌ๋ผ๋ช
const list = [{
name: 'ํ๊ธธ๋',
age: 15,
email: 'ํ๊ธธ๋@naver.com'
}, {
name: '๊น๊ธธ๋',
age: 44,
email: '๊น๊ธธ๋@naver.com'
}, {
name: '๋ฐ๊ธธ๋',
age: 26,
email: '๋ฐ๊ธธ๋@naver.com'
}];
const workBook = xlsx.utils.book_new();
const workSheet = xlsx.utils.json_to_sheet(list);
xlsx.utils.sheet_add_aoa(workSheet, header);
xlsx.utils.book_append_sheet(workBook, workSheet, sheetName);
xlsx.writeFile(workBook, fileName);
}
'๊ฐ๋ฐ > Vue.js' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
vue router / query vs params (0) | 2022.06.14 |
---|---|
$nextTick() (0) | 2022.04.18 |
Vue ์๋ช ์ฃผ๊ธฐ (0) | 2022.04.13 |
Vue3 Composition API (0) | 2022.04.06 |
Vuex / ์ํ๊ด๋ฆฌ / Vuex ํจํด ๋ฐ ์์ (0) | 2022.04.05 |
๋๊ธ