๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ๋ฐœ/Vue.js

Vue.js xlsx ์—‘์…€ ๋‹ค์šด๋กœ๋“œ

by 1mj 2022. 6. 16.

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

๋Œ“๊ธ€