UNPKG

easyexceljs

Version:

简单的操作生成漂亮的EXCEL,快速上手。提供漂亮模板直接使用

1 lines 16.1 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("exceljs"),require("file-saver")):"function"==typeof define&&define.amd?define(["exceljs","file-saver"],t):"object"==typeof exports?exports.easyExcel=t(require("exceljs"),require("file-saver")):e.easyExcel=t(e.exceljs,e["file-saver"])}(this,(function(e,t){return function(e){var t={};function r(o){if(t[o])return t[o].exports;var l=t[o]={i:o,l:!1,exports:{}};return e[o].call(l.exports,l,l.exports,r),l.l=!0,l.exports}return r.m=e,r.c=t,r.d=function(e,t,o){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var l in e)r.d(o,l,function(t){return e[t]}.bind(null,l));return o},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=4)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getExcelCellNoteDTO=t.getExcelCellStyle=t.ExcelStyleTemplate=void 0;var o=r(1);t.ExcelStyleTemplate={red:{rowStyle:{rowNum:1,rowBgColor:"FFFF0000",font:{name:"Arial",size:12,bold:!0,color:"ffffffff"}},cellStyle:{cellName:"",BorderColor:"FFFF0000",BorderStyle:"thin",font:{name:"Arial",size:11,bold:!0,color:"ff707b7c"}}},blue:{rowStyle:{rowNum:1,rowBgColor:"ff5faee3",font:{name:"Arial",size:12,bold:!0,color:"ffffffff"}},cellStyle:{cellName:"",BorderColor:"ff48c9b0",BorderStyle:"thin",font:{name:"Arial",size:11,bold:!0,color:"ff707b7c"}}},green:{rowStyle:{rowNum:1,rowBgColor:"ff48c9b0",font:{name:"Arial",size:12,bold:!0,color:"ffffffff"}},cellStyle:{cellName:"",BorderColor:"ffff0000",BorderStyle:"thin",font:{name:"Arial",size:11,bold:!0,color:"ff707b7c"}}},firebrick:{rowStyle:{rowNum:1,rowBgColor:"ffb22222",font:{name:"Arial",size:12,bold:!0,color:"ffffffff"}},cellStyle:{cellName:"",BorderColor:"ffb22222",BorderStyle:"thin",font:{name:"Arial",size:11,bold:!0,color:"ffb22222"}}}},t.getExcelCellStyle=function(e){var t=new o.CellStyleDTO;switch(e){case"red":t.BorderColor="ffff0000",t.BorderStyle="thin",t.font={name:"Malgun Gothic Semilight",size:11,bold:!0,color:"ffff0000"};break;case"blue":t.BorderColor="ff5faee3",t.BorderStyle="thin",t.font={name:"Malgun Gothic Semilight",size:11,bold:!0,color:"ff5faee3"};break;case"green":t.BorderColor="ff48c9b0",t.BorderStyle="thin",t.font={name:"Malgun Gothic Semilight",size:11,bold:!0,color:"ff48c9b0"};break;case"firebrick":t.BorderColor="ffb22222",t.BorderStyle="thin",t.font={name:"Malgun Gothic Semilight",size:11,bold:!0,color:"ffb22222"};break;default:t.BorderColor="",t.BorderStyle="",t.font={name:"宋体",size:11,bold:!1,color:"ff000000"}}return t},t.getExcelCellNoteDTO=function(){return new o.CellNoteDTO}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,r,o){return r&&e(t.prototype,r),o&&e(t,o),t}}();function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var n=function e(t){l(this,e),this.next=void 0,this.value=t},i=function(){function e(){l(this,e),this.node=null,this.size=0,this.tail=null,this.head=null,this.clear()}return o(e,[{key:"addNew",value:function(e){this.node=new n(e),this.head?(this.tail.next=this.node,this.tail=this.node):(this.tail=this.node,this.head=this.node),this.size++}},{key:"clear",value:function(){this.tail=null,this.head=null,this.size=0}},{key:"sizes",get:function(){return this.size}},{key:"getHead",get:function(){return this.head}}]),e}();t.baseModel=function(e){this.creator=e.creator||"默认用户",this.lastModifiedBy=e.lastModifiedBy||"",this.created=e.created||new Date,this.modified=e.modified||new Date,this.lastPrinted=e.lastPrinted||new Date,this.version="1.1.6"},t.CellStyleDTO=function(){return new Object({cellIndex:1,rowIndex:1,cellName:"",BorderColor:"",BorderStyle:"",font:{name:"",size:"",bold:"",color:""}})},t.CellNoteDTO=function(){return new Object({text:"",protection:{locked:!0,lockText:!1},editAs:"absolute"})},t.customSetNodeList=i},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e},l=function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var r=[],o=!0,l=!1,n=void 0;try{for(var i,s=e[Symbol.iterator]();!(o=(i=s.next()).done)&&(r.push(i.value),!t||r.length!==t);o=!0);}catch(e){l=!0,n=e}finally{try{!o&&s.return&&s.return()}finally{if(l)throw n}}return r}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")};function n(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}var i=r(3);function s(e,t){var r=Math.pow(2,31);if(!(e>=r||t>=r)){if(e<=0)return"A1";for(var o="",l="A".charCodeAt();e>0;)e--,o=String.fromCharCode(e%26+l)+o,e=(e-e%26)/26;return o+t}f(ALERT_MESSAGE.MAX_INTEGER)}var a=Object.prototype.toString;function c(e){switch(e){case"log":return function(e){console.log(e)};case"warn":return function(e){console.warn(e)};case"error":return function(e){console.error(e)}}}var f=c("warn"),u=c("error"),h=c("log");function d(e,t){!t.length>0||t.forEach((function(t){var r;r=t.cellName?t.cellName:s(t.cellIndex||1,t.rowIndex||1),t.BorderColor&&(e.getCell(r).border={top:{style:t.BorderStyle?t.BorderStyle:"",color:{argb:t.BorderColor}},left:{style:t.BorderStyle?t.BorderStyle:"",color:{argb:t.BorderColor}},bottom:{style:t.BorderStyle?t.BorderStyle:"",color:{argb:t.BorderColor}},right:{style:t.BorderStyle?t.BorderStyle:"",color:{argb:t.BorderColor}}}),t.font&&(e.getCell(r).font={name:t.font.name||"",color:{argb:t.font.color||""},family:2,size:t.font.size||11,bold:"boolean"==typeof t.font.bold?t.font.bold:""})}))}function y(e){return a.call(e).slice(8,-1)}t.getCellPosLetter=s,t.conWar=f,t.conErr=u,t.conLog=h,t._setCellStyle=d,t._setRowStyle=function(e,t){!t.length>0||t.forEach((function(t){var r=e.getRow(t.rowNum);r.height=t.height||21.5,r.fill={type:"gradient",gradient:"angle",degree:0,stops:[{position:0,color:{argb:t.rowBgColor}},{position:.5,color:{argb:t.rowBgColor}},{position:1,color:{argb:t.rowBgColor}}]},r.font={name:t.font.name,size:t.font.size,bold:t.font.bold,color:{argb:t.font.color}},r.commit()}))},t._setCellStyleByWhere=function(e){var t=this;this.setCellByWhere.forEach((function(r){for(var o=r.where,l=r.cellStyle,n=o.valueKey,i=o.whereType,s=o.whereValue,a=1,c=[],f=0;f<t.sheetColumnsData.length;f++)if(t.sheetColumnsData[f].key==n){a+=f;break}t.sheetRowsData.forEach((function(e,t){var r=e[n],o=0;switch(i.trim().toLowerCase()){case"<":o=r<s?t+1:0;break;case">":o=r>s?t+1:0;break;case"==":o=r==s?t+1:0;break;case"!=":o=r!=s?t+1:0;break;case"===":o=r===s?t+1:0;break;case"!==":o=r!==s?t+1:0;break;case"indexof":o=r.indexof(s)>-1?t+1:0;break;case"unindexof":o=-1===r.indexof(s)?t+1:0}o>0&&c.push(o)})),c.forEach((function(t){l.cellIndex=a,l.rowIndex=t,d(e,[l])}))}))},t._setCellByRowCellIndex=function(e){this.setCellByRowCellIndex.forEach((function(t){var r=l(t.ROW_CELL_INDEX,2),o=r[0],n=r[1],i=t.cellStyle;i.cellIndex=n||1,i.rowIndex=o||1,d(e,[i])}))},t._setCellNotes=function(e){this.setCellNotesIndex.forEach((function(t){var r=l(t.ROW_CELL_INDEX,2),o=r[0],n=r[1],i=t.NOTE_DTO;!function(e,t,r,o){var l=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],n=s(r||1,t||1),i={protection:{locked:o.protection.locked,lockText:o.protection.lockText},editAs:o.editAs};l&&(i.texts=[{font:{bold:!0,size:11,color:{argb:"ff696969",theme:1},name:"宋体",family:2,scheme:"minor"},text:o.text}]),e.getCell(n).note=i}(e,o,n,i)}))},t._setCurrentValue=function(e){for(var t=this,r=this.customList.getHead,o=function(){var o=r.value,n=o.rowCellIndex,i=o.callBack;if("Array"===y(n))n.forEach((function(r){var o=l(r,2),n=o[0],a=s(o[1]||1,n||1),c=e.getCell(a);i.call(t,c)}));else if("String"===y(n)&&42===n.charCodeAt(0))for(var a=t.sheetColumnsData.length,c=t.sheetRowsData.length+t.repairLength,f="",u=2;u<c;u++)for(var h=1;h<a;h++){f=s(h||1,u||1);var d=e.getCell(f);i.call(t,d)}r=r.next};r;)o()},t._isBasicType=function(e){"Array"===y(e.sheetColumnsData)?"Array"===y(e.sheetRowsData)?"String"===y(e.excelFileName)||u(ALERT_MESSAGE.MUST_FILENAME):u(ALERT_MESSAGE.MUST_ROW_TYPE):u(ALERT_MESSAGE.MUST_COLUMN_TYPE)},t._getWorkBook=function(e){var t=new i.Workbook;return t.creator=e.creator,t.lastModifiedBy=e.lastModifiedBy,t.created=e.created,t.modified=e.modified,t.lastPrinted=e.lastPrinted,t.properties.date1904=!0,t.calcProperties.fullCalcOnLoad=!0,t},t.getType=y,t._mergeCells=function(e){this.mergeCellsList.forEach((function(t){e.mergeCells(t)}))},t._alignmentCells=function(e){this.alignmentList.forEach((function(t){e.getCell(t.cellName).alignment=o({},t.alignment)}))},t._setRichText=function(e){this.richTextList.forEach((function(t){e.getCell(t.cellName).value={richText:[].concat(n(t.richText))}}))},t._setRowsHeight=function(e){this.rowsHeightList.forEach((function(t){var r=e.getRow(t.rowIndex);r.height=t.height?t.height:15,r.commit()}))},t._setImageInWorkBookBase64=function(e,t){this.imageBase64List.forEach((function(r){var o=e.addImage({base64:r.base64Image,extension:"png"});t.addImage(o,{tl:r.tl,ext:r.ext})}))},t.clearExcelOptions=function(){this.sheetColumnsData=[],this.sheetRowsData=[],this.rowStyleOptions=[],this.cellStyleOptions=[],this.setCellByWhere=[],this.setCellByRowCellIndex=[],this.setCellNotesIndex=[],this.customList.clear(),this.mergeCellsList=[],this.alignmentList=[],this.richTextList=[],this.rowsHeightList=[],this.imageBase64List=[]},t.isObject=function(e){return null!==e&&"Object"===a.call(e).slice(8,-1)}},function(t,r){t.exports=e},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getExcelCellNoteDTO=t.getExcelCellStyle=t.ExcelStyleTemplate=t.getCellPosLetter=t.createExcelByOneSheet=void 0;var o,l=r(0),n=r(2),i=r(5),s=(o=i)&&o.__esModule?o:{default:o};t.createExcelByOneSheet=s.default,t.getCellPosLetter=n.getCellPosLetter,t.ExcelStyleTemplate=l.ExcelStyleTemplate,t.getExcelCellStyle=l.getExcelCellStyle,t.getExcelCellNoteDTO=l.getExcelCellNoteDTO},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e},l=r(6),n=r(2),i=r(7),s=r(1),a=r(0);r(3);function c(e){this instanceof c?e?(s.baseModel.call(this,e),this.sheetName=e.sheetName||"sheet1",this.sheetColumnsData=[],this.sheetRowsData=[],this.excelFileName=e.excelFileName||"excel",this.rowStyleOptions=[],this.cellStyleOptions=[],this.setCellByWhere=[],this.setCellByRowCellIndex=[],this.setCellNotesIndex=[],this.customList=new s.customSetNodeList,this.repairLength=0,this.mergeCellsList=[],this.alignmentList=[],this.rowsHeightList=[],this.richTextList=[],this.imageBase64List=[]):(0,n.conErr)(i.ALERT_MESSAGE.MUST_ARGUMENTS):(0,n.conErr)(i.ALERT_MESSAGE.MUST_NEW)}c.prototype.getColumnBaseStructure=function(){return{header:"column Name",key:"column Key",width:20}},c.prototype.saveAsExcel=function(){var e=this;return(0,n._isBasicType)(this),new Promise((function(t,r){var i=(0,n._getWorkBook)(e),s=i.addWorksheet(e.sheetName);e.sheetColumnsData.length>0&&(s.columns=[].concat(function(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}(e.sheetColumnsData))),e.sheetRowsData.forEach((function(e){s.addRow(o({},e))})),(0,n._setRowStyle)(s,e.rowStyleOptions),e.setCellByWhere.length>0&&n._setCellStyleByWhere.call(e,s),e.setCellByRowCellIndex.length>0&&n._setCellByRowCellIndex.call(e,s),e.setCellNotesIndex.length>0&&n._setCellNotes.call(e,s),e.mergeCellsList.length>0&&n._mergeCells.call(e,s),e.alignmentList.length>0&&n._alignmentCells.call(e,s),e.richTextList.length>0&&n._setRichText.call(e,s),e.rowsHeightList.length>0&&n._setRowsHeight.call(e,s),e.imageBase64List.length>0&&n._setImageInWorkBookBase64.call(e,i,s),e.customList.sizes>0&&n._setCurrentValue.call(e,s),e.excelFileName=e.excelFileName.lastIndexOf(".xlsx")>-1?e.excelFileName:e.excelFileName+".xlsx",i.xlsx.writeBuffer().then((function(t){var r=new Blob([t],{type:""});(0,l.saveAs)(r,e.excelFileName),n.clearExcelOptions.call(e)}))}))},c.prototype.setCellStyleByWhere=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;t||(t=new a.getExcelCellStyle);var r=e;if((0,n.isObject)(r))return this.setCellByWhere.push({where:r,cellStyle:t}),this;(0,n.conErr)(i.ALERT_MESSAGE.OBJECT_TYPE)},c.prototype.setCellStyleByRowCellIndex=function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;if(r||(r=new a.getExcelCellStyle),e.constructor===Array)return e.forEach((function(e){t.setCellByRowCellIndex.push({ROW_CELL_INDEX:e,cellStyle:r})})),this;(0,n.conErr)(i.ALERT_MESSAGE.ROWCELL_INDEX_TYPE)},c.prototype.setCellNoteTextByRowCellIndex=function(e,t){var r=this;return e.constructor!==Array&&noteDatas.constructor!==Array?((0,n.conErr)(i.ALERT_MESSAGE.ROWCELL_INDEX_TYPE),void(0,n.conErr)(i.ALERT_MESSAGE.NOTES_INDEX_TYPE)):(e.forEach((function(e,o){var l=new a.getExcelCellNoteDTO;l.text=t[o],r.setCellNotesIndex.push({ROW_CELL_INDEX:e,NOTE_DTO:l})})),this)},c.prototype.mergeCells=function(e){if(void 0===e)return this;var t=this;this.mergeCellsList.push(e);return function e(r){return void 0===r?t:("String"===(0,n.getType)(r)&&t.mergeCellsList.push(r),e)}},c.prototype.alignmentCells=function(e){if(void 0===e)return this;this.alignmentList.push(e);var t=this;return function e(r){return void 0===r?t:("Object"===(0,n.getType)(r)&&t.alignmentList.push(r),e)}},c.prototype.RichTextCells=function(e){if(void 0===e)return this;this.richTextList.push(e);var t=this;return function e(r){return void 0===r?t:("Object"===(0,n.getType)(r)&&t.richTextList.push(r),e)}},c.prototype.rowsHeight=function(e){if(void 0===e)return this;this.rowsHeightList.push(e);var t=this;return function e(r){return void 0===r?t:("Object"===(0,n.getType)(r)&&t.rowsHeightList.push(r),e)}},c.prototype.ImageInWorkBookBase64=function(e){if(void 0===e)return this;this.imageBase64List.push(e);var t=this;return function e(r){return void 0===r?t:(this.imageBase64List.push(r),e)}},c.prototype.customSetValueByIndex=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if("Function"===(0,n.getType)(t)){var o={rowCellIndex:[],callBack:void 0};return e.constructor!==Array&&42===e.charCodeAt(0)?o.rowCellIndex=e:e.constructor===Array&&e.forEach((function(e,t){o.rowCellIndex.push(e)})),o.callBack=t,this.repairLength=r,this.customList.addNew(o),this}(0,n.conErr)(i.ALERT_MESSAGE.MUST_FUNCTION)},t.default=c,e.exports=t.default},function(e,r){e.exports=t},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.ALERT_MESSAGE={MUST_NEW:"请new出来",MUST_ARGUMENTS:"请传入基本的必传参数",MUST_COLUMN_TYPE:"sheet‘表格头 sheetColumnsData’内容定义必须为数组形式",MUST_ROW_TYPE:"sheet‘表格行 sheetRowsData’内容定义必须为数组形式",MUST_FILENAME:"excel名称不能为空",MAX_INTEGER:"不要超过integer最大值",OBJECT_TYPE:"必须传入非Null的O对象",ROWCELL_INDEX_TYPE:"rowCellIndex必须是数组类型, [[rowIndex,cellIndex],[rowIndex,cellIndex]]",NOTES_INDEX_TYPE:"NOTES必须是数组类型, [noteDTO,noteDTO]",MUST_FUNCTION:"callBack必须是一个function"}}])}));