티스토리 뷰
반응형
필요한 모듈 설치
npm install xlsx
xlsx에 내장된 함수들은 아래의 링크 참조
https://www.npmjs.com/package/xlsx
xlsx
SheetJS Spreadsheet data parser and writer. Latest version: 0.18.5, last published: a month ago. Start using xlsx in your project by running `npm i xlsx`. There are 3029 other projects in the npm registry using xlsx.
www.npmjs.com
const fs = require("fs");
const xlsx = require("xlsx");
resultText.push({
col1: '컬럼1 내용',
col2: '컬럼2 내용',
col3: '컬럼3 내용'
});
const filePath = `example.xlsx`;
//파일이 존재할 경우 삭제
if (fs.existsSync(filePath)) {
fs.unlinkSync(filePath);
}
const EXCEL = xlsx.utils.book_new();
//Header : Excel의 컬럼 부분
//resultText : EXCEL의 내용
const EXCEL_CONTENT = xlsx.utils.json_to_sheet(resultText, {
header: ["컬럼1", "컬럼2", "컬럼3"],
skipHeader: false, //Header 안보이게_FALSE : 컬럼1,컬럼2,컬럼3 안보임
});
//sheet 이름
xlsx.utils.book_append_sheet(EXCEL, EXCEL_CONTENT, "원하는 Sheet 이름 입력");
//새로운 엑셀 파일 생성
xlsx.writeFile(EXCEL, filePath);
* 데이터가 array 일 경우 xlsx.utils.json_to_sheet() 부분을 xlsx.utils.array_to_sheet() 으로 변경해서 사용
반응형
'Server' 카테고리의 다른 글
[node.js] Client 한테 FormData() 전달받아 File 저장하기 (feat Multer..) (0) | 2022.05.10 |
---|---|
[node.js] pdfkit 사용하여 동적으로 pdf 파일 만들기 (0) | 2022.05.08 |
[node.js] base 64 이미지 decode 및 저장 방법 (0) | 2022.05.04 |
[Express] http로 접속시 https로 redirect (0) | 2022.05.03 |
[Express] session mySQL에 저장하기 (0) | 2022.05.03 |
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- mysql date between performance
- mysql date between # mysql date between 대소 비교 연산자
- linux/amd64/v2
- PDF #pdfkit
- reack-cookies #아이디 저장하기 #react 아이디 저장 #react cookie #리엑트 아이디 저장하기
- docker # docker build # m1 docker build
- 이미지 전송 # 이미지 업로드 #이미지 여러장 #이미지 여러장 업로드 #react 이미지 업로드 #react 이미지 여러장 업로드
- AWS #인바운드 #SSH #인스턴스 연결
- docker mysql
- Swal #sweetalert2 #alert #알림창 띄우기 #react swal
- mysql date
- react #react-spinners #modal loading #overlay #로딩창 #react 로딩창 만들기
- node.js 파일 저장
- excel 파일 만들기 #node.js #express excel 파일 만들기 #데이터 입력해서 excel 파일 만들기
- ec2 instance connect is unable to connect to your instance. ensure your instance network settings are configured correctly for ec2 instance connect. for more information
- React filter #js Includes #React Filter includes
- FormData #FormData 파일전송 #FormData append json # React FormData File #React FormData append Json
- supported: linux/amd64
- see ec2 instance connect prerequisites at https://docs.aws.amazon.com/awsec2/latest/userguide #인스턴스 연결 안됨
- BOJ #JS
- Express multer #Express File 저장 #node.js
- PoolCluster : Error: connect ECONNREFUSED 127.0.0.1:3306)
- JavaScript #Programmers #lvl2 #프로그래머스 오픈채팅방 # 오픈채팅방 문제
- Mac docker.for.mac.host.internal
- ERROR: failed to solve: no support for running processes with linux/amd64/v3 platform
- node.js #node.js pdf만들기 #node.js pdfkit
- react #img 전송
- mysql date type
- Procedure #mysql #mysql Procedure #mysql 반복문 #Procedure 반복문 #mysql insert 반복문
- Pytorch #Yolov5 #Segementation
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
글 보관함