본문 바로가기

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' 카테고리의 다른 글

Node.js에서 SMS 보내기(COOLSMS사용)  (0) 2024.09.21
React에서 파일 다운로드 구현  (0) 2024.08.22
.env 환경변수 설정  (0) 2024.08.16
React 정보를 Unity로 보내기  (0) 2024.05.08
Unity build 내용을 web에 띄워보자  (0) 2024.05.05