'use strict' /** * Copyright (c) 2018~2020, OBCon Inc. * All rights reserved. */ /** * @file * @copyright OBCon Inc. Korea 2018~2020 * @author gye hyun james kim [pnuskgh@gmail.com] */ //--- https://www.npmjs.com/package/excel4node let excel4node = require('excel4node'); class Excel { constructor() { this._filename = null; //--- ~.xlsx this._workbook = null; this.widthCalc = 0.56; this._row = 1; this._col = 1; this.initStyle(); } get filename() { return this._filename; } set filename(newValue) { this._filename = newValue; } get workbook() { return this._workbook; } set workbook(newValue) { this._workbook = newValue; } get row() { return this._row; } set row(newValue) { this._row = newValue; } addRow(cnt=1) { this._row = this._row + cnt; return this._row; } get col() { return this._col; } set col(newValue) { this._col = newValue; } addCol(cnt=1) { this._col = this._col + cnt; return this._col; } initWorkbook() { this._workbook = new excel4node.Workbook({ jszip: { compression: 'DEFLATE' }, defaultFont: { size: 10, name: '맑은 고딕', color: '#000000' } }); } initStyle() { this.styleLeft = { alignment: { horizontal: 'left' } }; this.styleCenter = { alignment: { horizontal: 'center' } }; this.styleRight = { alignment: { horizontal: 'right' } }; this.styleTop = { alignment: { vertical: 'top' } }; this.styleMiddle = { alignment: { vertical: 'center' } }; this.styleBottom = { alignment: { vertical: 'bottom' } }; this.styleString = { font: { color: '#000000', size: 10 } }; this.styleDate = { font: { color: '#000000', size: 10 }, dateFormat: 'yyyy/m/d hh:mm:ss', numberFormat: 'yyyy/m/d hh:mm:ss' }; this.styleInteger = { font: { color: '#000000', size: 10 }, numberFormat: '###,##0; -###,##0; 0' }; this.styleNumber = { font: { color: '#000000', size: 10 }, numberFormat: '###,##0.00; -###,##0.00; 0' }; this.styleBorder = { border: { left: { style: 'thin', color: '#000000' }, right: { style: 'thin', color: '#000000' }, top: { style: 'thin', color: '#000000' }, bottom: { style: 'thin', color: '#000000' } } }; this.styleTitle = { font: { bold: true, color: '#000000', size: 24 }, fill: { type: 'pattern', bgColor: '#ffffff', fgColor: '#ffffff', patternType: 'solid' }, }; //--- 문서에서 유용하게 사용하는 스타일 정의 //--- aqua, black, blue, blue-gray, bright green, brown, dark blue, dark green, dark red, dark teal, //--- dark yellow, gold, gray-25, gray-40, gray-50, gray-80, green, indigo, lavender, light blue, //--- light green, light orange, light turquoise, light yellow, lime, olive green, orange, pale blue, pink, plum, //--- red, rose, sea green, sky blue, tan, teal, turquoise, violet, white, yellow this.styleTableHeader = { font: { bold: true, color: '#ffffff', size: 10 }, fill: { type: 'pattern', bgColor: '#595959', fgColor: '#595959', patternType: 'solid' }, border: { left: { style: 'thin', color: '#000000' }, right: { style: 'thin', color: '#000000' }, top: { style: 'thin', color: '#000000' }, bottom: { style: 'thin', color: '#000000' } } }; this.styleTableBody = { font: { color: '#000000', size: 10 }, border: { left: { style: 'thin', color: '#000000' }, right: { style: 'thin', color: '#000000' }, top: { style: 'thin', color: '#000000' }, bottom: { style: 'thin', color: '#000000' } } }; } makeWorksheet(sheetName) { let options = { margins: { left: 1.5, right: 1.5, }, }; return this._workbook.addWorksheet(sheetName, options); } } module.exports = Excel;