본문 바로가기

WEB

node.js 에서 Excel로 데이터 저장

728x90

 

터미널에 라이브러리 다운을 위한 npm install 진행 

npm install exceljs

 

사용 코드 

// 라이브러리 사용을 위한 선언
const ExcelJS = require('exceljs');
const workbook = new ExcelJS.Workbook();
const sheet = workbook.addWorksheet('Data');

// 행 합치기
sheet.mergeCells('A1:D1');
// 데이터 삽입
sheet.getCell('A1').value = `Date: ${new Date().toLocaleString() }`;

// 날짜와 시간 셀의 정렬 설정 (가운데 정렬 & 굵은 글씨)
sheet.getCell('A1').alignment = {horizontal: 'center' };
sheet.getCell('A1').font = {bold: true};

// data.xlsx 이름의 엑셀파일 생성
workbook.xlsx.writeFile('data.xlsx')

 

결과

'WEB' 카테고리의 다른 글