본문 바로가기

Node.js

Node.js excel file download 엑셀 다운로드 사용법 예제

반응형

 

Node.js Typescript Exceljs 로 엑셀파일 다운로드되도록 만들기 

How to download exce(.xlsx) file in Node.js with TypeScript 

 

const exec = async (res) => {

	workbook 및 worksheet 생성 

  res.setHeader(
    'Content-Type',
    'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  );

  res.setHeader(
    'Content-Disposition',
    `attachment; filename=${fileName}.xlsx`,
  );

  await workbook.xlsx.write(res);

};

export default { exec };

controller

class controller {

  public exportExcel(req: Request, res: Response): object {

	return service
      .exportExcelService(res)
      .then(() => {
        res.status(200).end();
      })
      .catch(mResponse.handleError(res));
  }
}

export const controller = new Controller();

 

 

반응형