Repository: JackGit/table2excel.js Branch: master Commit: 0c9b3db89f2a Files: 31 Total size: 91.6 KB Directory structure: gitextract_ca7o4bbr/ ├── .babelrc ├── .gitignore ├── README.md ├── dist/ │ └── table2excel.core.js ├── docs/ │ ├── index.html │ └── js/ │ └── table2excel.core.js ├── es5/ │ ├── constants.js │ ├── index.js │ ├── plugins/ │ │ ├── alignment.js │ │ ├── autoWidth.js │ │ ├── fill.js │ │ ├── font.js │ │ ├── form.js │ │ ├── hyperlink.js │ │ └── index.js │ ├── table2excel.js │ └── utils.js ├── package.json ├── src/ │ ├── constants.js │ ├── index.js │ ├── plugins/ │ │ ├── alignment.js │ │ ├── autoWidth.js │ │ ├── fill.js │ │ ├── font.js │ │ ├── form.js │ │ ├── hyperlink.js │ │ └── index.js │ ├── table2excel.js │ └── utils.js ├── webpack.core.config.js └── webpack.umd.config.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .babelrc ================================================ { "presets":[ "es2015", "stage-1" ] } ================================================ FILE: .gitignore ================================================ # Logs logs *.log npm-debug.log* yarn-debug.log* yarn-error.log* # Runtime data pids *.pid *.seed *.pid.lock # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage # nyc test coverage .nyc_output # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt # Bower dependency directory (https://bower.io/) bower_components # node-waf configuration .lock-wscript # Compiled binary addons (http://nodejs.org/api/addons.html) build/Release # Dependency directories node_modules/ jspm_packages/ # Typescript v1 declaration files typings/ # Optional npm cache directory .npm # Optional eslint cache .eslintcache # Optional REPL history .node_repl_history # Output of 'npm pack' *.tgz # Yarn Integrity file .yarn-integrity # dotenv environment variables file .env ================================================ FILE: README.md ================================================ # Table2Excel.js This is a library to export html tables to excel sheets. ## Precondition It has to be a row * column table ## Features 1. able to export with width, alignment and colors 2. extendable ## Dependencies [ExcelJS](https://github.com/guyonroche/exceljs) [FileSaver.js](https://github.com/eligrey/FileSaver.js) ## Live Demo [Demo](https://jackgit.github.io/table2excel.js/index.html) ## Include table2excel.js ### npm `ExcelJS` is peer dependency to `table2excel.js`, so you need to install exceljs first: ```bash npm i exceljs ``` then, install table2excel.js: ```bash npm i table2excel.js ``` use in your code like: ```js import Table2Excel from 'table2excel.js' new Table2Excel('table').export() ``` you may also need a config in webpack: ```js node: { fs: 'empty' } ``` ### table2excel.min.js (with ExcelJS packed) ```html ``` ### table2excel.core.js (without ExcelJS packed) ```html ``` ## Basic Usage ```js const table2Excel = new Table2Excel(selector, options) // new Table2Excel('table') table2Excel.export(fileName, extension) // table2Excel.export('my-exported-table', 'xlsx') ``` `extension` can be `'xls'` or `'xlsx'`, default as `'xlsx'` ### selector It's optional, and defaulted as `'table'` ### options It's optional, and defaulted as: ```js { workbook: { views: [{ x: 0, y: 0, width: 10000, height: 20000, firstSheet: 0, activeTab: 1, visibility: 'visible' }] }, widthRatio: .14, plugins: [ Table2Excel.plugins.fontPlugin, Table2Excel.plugins.fillPlugin, Table2Excel.plugins.formPlugin, Table2Excel.plugins.alignmentPlugin, Table2Excel.plugins.hyperlinkPlugin, Table2Excel.plugins.autoWidthPlugin ] } ``` `workbook` is options used while creating a workbook, please refer [exceljs#create-a-workbook](https://github.com/guyonroche/exceljs#create-a-workbook) for details. `widthRatio` is a ratio that will be used while converting `width` style of html table cells to width of sheet cells. ## Plugins Plugin helps to extend the ability of transforming table to excel. Build-in plugins can be access like: ```js Table2Excel.plugins.fontPlugin, Table2Excel.plugins.fillPlugin, Table2Excel.plugins.formPlugin, Table2Excel.plugins.alignmentPlugin, Table2Excel.plugins.hyperlinkPlugin, Table2Excel.plugins.autoWidthPlugin ``` A plugin can be defined to join different phase of table to excel process, and in different phase, plugin is able to access different objects from context. ```js { /** * after an empty workbook created * @param {ExcelJS.Workbook} context.workbook * @param {NodeList} context.tables */ workbookCreated ({ workbook, tables }) {}, /** * after an empty worksheet created * @param {ExcelJS.Workbook} workbook * @param {NodeList} tables * @param {ExcelJS.Worksheet} worksheet * @param {HTMLTableElement} table */ worksheetCreated ({ workbook, tables, worksheet, table }) {}, /** * after a worksheet been filled with data from table * @param {ExcelJS.Workbook} workbook * @param {NodeList} tables * @param {ExcelJS.Worksheet} worksheet * @param {HTMLTableElement} table */ worksheetCompleted ({ workbook, tables, worksheet, table }) {}, /** * after an cell of worksheet created * @param {ExcelJS.Workbook} workbook * @param {NodeList} tables * @param {ExcelJS.Worksheet} worksheet * @param {HTMLTableElement} table * @param {ExcelJS.Cell} workcell * @param {HTMLTableCellElement} cell * @param {colRange} [from, to] * @param {rowRange} [from, to] */ workcellCreated ({ workbook, tables, worksheet, table, workcell, cell, cellStyle, colRange, rowRange }) {} } ``` Example 1, you can define a plugin to make some rows or columns hidden of exported excel: ```js const table2Excel = new Table2Excel('table', { plugins: [{ worksheetCompleted ({ workbook, tables, worksheet, table }) { worksheet.getRow(1).hidden = true worksheet.getColumn(1).hidden = true } }] }) ``` Example 2, you can add your customized cell parser for your table: ```js const table2Excel = new Table2Excel('table', { plugins: [{ workcellCreated ({ workbook, tables, worksheet, table, workcell, cell, cellStyle, rowRange, colRange }) { workcell.value = { text: '', link: '' } workcell.style = { ...workcell.style, font: {}, color: {} } } }] }) ``` ================================================ FILE: dist/table2excel.core.js ================================================ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("ExcelJS")):"function"==typeof define&&define.amd?define(["ExcelJS"],t):"object"==typeof exports?exports.Table2Excel=t(require("ExcelJS")):e.Table2Excel=t(e.ExcelJS)}(window,function(e){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=3)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.argb=t.mergeCells=t.cellPosition=t.columnIndex=t.saveAsExcel=void 0;var r=n(1),o=n(6),l=(t.saveAsExcel=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"table",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"xlsx",l=r.MIME_TYPES[n];l?e.xlsx.writeBuffer().then(function(e){(0,o.saveAs)(new Blob([e.buffer],{type:l}),t+"."+n)}):console.error(n+" file extension is not supported")},function(e){var t="A".charCodeAt(0);return String.fromCharCode(t+e-1)}),i=t.columnIndex=function(e){var t=void 0;if((e+=1)<=26)t=l(e);else{var n=e%26,r=Math.floor(e/26);t=0===n?l(r-1)+l(26):l(r)+l(n)}return t},a=t.cellPosition=function(e,t){return""+i(e)+(t+1)};t.mergeCells=function(e,t,n,r,o){var l=a(t,n),i=a(r,o);return e.mergeCells(l,i),e.getCell(l)},t.argb=function(e){var t=e.split("(")[1].split(")")[0].split(",").map(function(e,t){return 3===t?255*e:e});return 3===t.length&&t.push(255),t.unshift(t.pop()),t.map(function(e){var t=parseInt(e).toString(16);return 1===t.length?"0"+t:t}).join("").toUpperCase()}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.MIME_TYPES={xls:"application/vnd.ms-excel",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"},t.WIDTH_RATIO=.14},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=c(n(9)),o=c(n(10)),l=c(n(11)),i=c(n(12)),a=c(n(13)),u=c(n(14));function c(e){return e&&e.__esModule?e:{default:e}}t.default={fontPlugin:r.default,fillPlugin:o.default,formPlugin:l.default,alignmentPlugin:i.default,hyperlinkPlugin:a.default,autoWidthPlugin:u.default}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=i(n(4)),o=i(n(2)),l=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}(n(0));function i(e){return e&&e.__esModule?e:{default:e}}r.default.plugins=o.default,r.default.utils=l,t.default=r.default},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:"table",r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.tables=Array.from("string"==typeof n?document.querySelectorAll(n):n),this.options=Object.assign({},f,r),this.plugins={},c.forEach(function(e){t.plugins[e]=t.options.plugins.filter(function(t){return t[e]}).map(function(t){return t[e]})}),this.pluginContext={}}return r(e,[{key:"_invokePlugin",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.pluginContext=Object.assign({},this.pluginContext,n),this.plugins[e].forEach(function(e){return e.call(t,t.pluginContext)})}},{key:"toExcel",value:function(){var e=this,t=this.tables,n=this.options,r=new o.default.Workbook;return Object.assign(r,n),this._invokePlugin("workbookCreated",{workbook:r,tables:t}),t.forEach(function(t,n){var o=r.addWorksheet("Sheet "+(n+1));e._invokePlugin("worksheetCreated",{worksheet:o,table:t}),e.toSheet(t,o),e._invokePlugin("worksheetCompleted",{worksheet:o,table:t})}),this.workbook=r}},{key:"toSheet",value:function(e,t){var n=this,r=e.rows.length,o=0;if(e.rows.length>0)for(var i=0;i600})}}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=Object.assign||function(e){for(var t=1;t0&&void 0!==arguments[0]?arguments[0]:"",t=["top","middle","bottom"],n=0;n0&&void 0!==arguments[0]?arguments[0]:"",t=["right","left","center","justify"],n=0;n

Table 1

1 github
c

ASCII Table

Binary Oct Dec Hex Abbreviation [b] [c] [d] Name ('67)
'63 '65 '67
000 0000 000 0 00 NULL NUL ^@ \0 Null
000 0001 001 1 01 SOM SOH ^A Start of Heading
000 0010 002 2 02 EOA STX ^B Start of Text
000 0011 003 3 03 EOM ETX ^C End of Text
000 0100 004 4 04 EOT ^D End of Transmission
000 0101 005 5 05 WRU ENQ ^E Enquiry
000 0110 006 6 06 RU ACK ^F Acknowledgement
000 0111 007 7 07 BELL BEL ^G \a Bell
000 1000 010 8 08 FE0 BS ^H \b Backspace[e][f]
000 1001 011 9 09 HT/SK HT ^I \t Horizontal Tab[g]
000 1010 012 10 0A LF ^J \n Line Feed
000 1011 013 11 0B VTAB VT ^K \v Vertical Tab
000 1100 014 12 0C FF ^L \f Form Feed
000 1101 015 13 0D CR ^M \r Carriage Return[h]
000 1110 016 14 0E SO ^N Shift Out
000 1111 017 15 0F SI ^O Shift In
001 0000 020 16 10 DC0 DLE ^P Data Link Escape
001 0001 021 17 11 DC1 ^Q Device Control 1 (often XON)
001 0010 022 18 12 DC2 ^R Device Control 2
001 0011 023 19 13 DC3 ^S Device Control 3 (often XOFF)
001 0100 024 20 14 DC4 ^T Device Control 4
001 0101 025 21 15 ERR NAK ^U Negative Acknowledgement
001 0110 026 22 16 SYNC SYN ^V Synchronous Idle
001 0111 027 23 17 LEM ETB ^W End of Transmission Block
001 1000 030 24 18 S0 CAN ^X Cancel
001 1001 031 25 19 S1 EM ^Y End of Medium
001 1010 032 26 1A S2 SS SUB ^Z Substitute
001 1011 033 27 1B S3 ESC ^[ \e[i] Escape[j]
001 1100 034 28 1C S4 FS ^\ File Separator
001 1101 035 29 1D S5 GS ^] Group Separator
001 1110 036 30 1E S6 RS ^^[k] Record Separator
001 1111 037 31 1F S7 US ^_ Unit Separator
111 1111 177 127 7F DEL ^? Delete[l][f]

Table 3

族→ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 电子层 0族电子数

周期↓ IA VIIIA
(0)
1 1
H

1.008
II A III A IV A V A VI A VII A 2
He

4.003





K





2
2 3
Li

6.941
4
Be

9.012
5
B

10.81
6
C

12.01
7
N

14.01
8
O

16.00
9
F

19.00
10
Ne

20.18




L
K




8
2
3 11
Na

22.99
12
Mg

24.31
III B IV B V B VI B VII B VIII B
I B II B 13
Al

26.98
14
Si

28.09
15
P

30.97
16
S

32.07
17
Cl

35.45
18
Ar

39.95



M
L
K



8
8
2
4 19
K

39.10
20
Ca

40.08
21
Sc

44.96
22
Ti

47.88
23
V

50.94
24
Cr

52.00
25
Mn

54.94
26
Fe

55.85
27
Co

58.93
28
Ni

58.69
29
Cu

63.55
30
Zn

65.39
31
Ga

69.72
32
Ge

72.59
33
As

74.92
34
Se

78.96
35
Br

79.90
36
Kr

83.80


N
M
L
K


8
18
8
2
5 37
Rb

85.47
38
Sr

87.62
39
Y

88.91
40
Zr

91.22
41
Nb

92.91
42
Mo

95.94
43
Tc

(97.91)
44
Ru

101.1
45
Rh

102.9
46
Pd

106.4
47
Ag

107.9
48
Cd

112.4
49
In

114.8
50
Sn

118.7
51
Sb

121.8
52
Te

127.6
53
I

126.9
54
Xe

131.3

O
N
M
L
K

8
18
18
8
2
6 55
Cs

132.9
56
Ba

137.3
57-
71
镧系
元素
72
Hf

178.5
73
Ta

180.9
74
W

183.9
75
Re

186.2
76
Os

190.2
77
Ir

192.2
78
Pt

195.1
79
Au

197.0
80
Hg

200.6
81
Tl

204.4
82
Pb

207.2
83
Bi

209.0
84
Po

(209.0)
85
At

(210.0)
86
Rn

(222.0)
P
O
N
M
L
K
8
18
32
18
8
2
7 87
Fr

(223.0)
88
Ra

(226.0)
89-
103
锕系
元素
104
Rf
𬬻(鑪)
(265.1)
105
Db
𬭊(𨧀)
(268.1)
106
Sg
𬭳(𨭎)
(271.1)
107
Bh
𬭛(𨨏)
(270.1)
108
Hs
𬭶(𨭆)
(277.2)
109
Mt
鿏(䥑)
(276.2)
110
Ds
𫟼(鐽)
(281.2)
111
Rg
𬬭(錀)
(280.2)
112
Cn
鿔(鎶)
(285.2)
113
Nh
缺字图片
(284.2)
114
Fl
𫓧(鈇)
(289.2)
115
Mc

(288.2)
116
Lv
𫟷(鉝)
(293.2)
117
Ts
缺字图片
(294.2)
118
Og
缺字图片
(294.2)
Q
P
O
N
M
L
K
8
18
32
32
18
8
2
镧系元素 57
La

138.9
58
Ce

140.1
59
Pr

140.9
60
Nd

144.2
61
Pm

(144.9)
62
Sm

150.4
63
Eu

152.0
64
Gd

157.3
65
Tb

158.9
66
Dy

162.5
67
Ho

164.9
68
Er

167.3
69
Tm

168.9
70
Yb

173.0
71
Lu

175.0
锕系元素 89
Ac

(227.0)
90
Th

232.0
91
Pa

231.0
92
U

238.0
93
Np

(237.1)
94
Pu

(244.1)
95
Am

(243.1)
96
Cm

(247.1)
97
Bk

(247.1)
98
Cf

(252.1)
99
Es

(252.1)
100
Fm

(257.1)
101
Md

(258.1)
102
No

(259.1)
103
Lr

(262.1)
================================================ FILE: docs/js/table2excel.core.js ================================================ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("ExcelJS")):"function"==typeof define&&define.amd?define(["ExcelJS"],t):"object"==typeof exports?exports.Table2Excel=t(require("ExcelJS")):e.Table2Excel=t(e.ExcelJS)}(window,function(e){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=3)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.argb=t.mergeCells=t.cellPosition=t.columnIndex=t.saveAsExcel=void 0;var r=n(1),o=n(6),l=(t.saveAsExcel=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"table",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"xlsx",l=r.MIME_TYPES[n];l?e.xlsx.writeBuffer().then(function(e){(0,o.saveAs)(new Blob([e.buffer],{type:l}),t+"."+n)}):console.error(n+" file extension is not supported")},function(e){var t="A".charCodeAt(0);return String.fromCharCode(t+e-1)}),i=t.columnIndex=function(e){var t=void 0;if((e+=1)<=26)t=l(e);else{var n=e%26,r=Math.floor(e/26);t=0===n?l(r-1)+l(26):l(r)+l(n)}return t},a=t.cellPosition=function(e,t){return""+i(e)+(t+1)};t.mergeCells=function(e,t,n,r,o){var l=a(t,n),i=a(r,o);return e.mergeCells(l,i),e.getCell(l)},t.argb=function(e){var t=e.split("(")[1].split(")")[0].split(",").map(function(e,t){return 3===t?255*e:e});return 3===t.length&&t.push(255),t.unshift(t.pop()),t.map(function(e){var t=parseInt(e).toString(16);return 1===t.length?"0"+t:t}).join("").toUpperCase()}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.MIME_TYPES={xls:"application/vnd.ms-excel",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"},t.WIDTH_RATIO=.14},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=c(n(9)),o=c(n(10)),l=c(n(11)),i=c(n(12)),a=c(n(13)),u=c(n(14));function c(e){return e&&e.__esModule?e:{default:e}}t.default={fontPlugin:r.default,fillPlugin:o.default,formPlugin:l.default,alignmentPlugin:i.default,hyperlinkPlugin:a.default,autoWidthPlugin:u.default}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=i(n(4)),o=i(n(2)),l=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}(n(0));function i(e){return e&&e.__esModule?e:{default:e}}r.default.plugins=o.default,r.default.utils=l,t.default=r.default},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:"table",r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.tables=Array.from("string"==typeof n?document.querySelectorAll(n):n),this.options=Object.assign({},f,r),this.plugins={},c.forEach(function(e){t.plugins[e]=t.options.plugins.filter(function(t){return t[e]}).map(function(t){return t[e]})}),this.pluginContext={}}return r(e,[{key:"_invokePlugin",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.pluginContext=Object.assign({},this.pluginContext,n),this.plugins[e].forEach(function(e){return e.call(t,t.pluginContext)})}},{key:"toExcel",value:function(){var e=this,t=this.tables,n=this.options,r=new o.default.Workbook;return Object.assign(r,n),this._invokePlugin("workbookCreated",{workbook:r,tables:t}),t.forEach(function(t,n){var o=r.addWorksheet("Sheet "+(n+1));e._invokePlugin("worksheetCreated",{worksheet:o,table:t}),e.toSheet(t,o),e._invokePlugin("worksheetCompleted",{worksheet:o,table:t})}),this.workbook=r}},{key:"toSheet",value:function(e,t){var n=this,r=e.rows.length,o=0;if(e.rows.length>0)for(var i=0;i600})}}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=Object.assign||function(e){for(var t=1;t0&&void 0!==arguments[0]?arguments[0]:"",t=["top","middle","bottom"],n=0;n0&&void 0!==arguments[0]?arguments[0]:"",t=["right","left","center","justify"],n=0;n 'right' * 'right' -> 'right' * etc... */ var getHorizontalAlign = function getHorizontalAlign() { var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; var aligns = ['right', 'left', 'center', 'justify']; for (var i = 0; i < aligns.length; i++) { if (value.includes(aligns[i])) { return aligns[i]; } } }; /** * 'baseline' -> 'middle' * 'text-top' -> 'top' * 'text-bottom' -> 'bottom' * 'sub' -> 'top' * 'super' -> 'bottom' */ var getVerticalAlign = function getVerticalAlign() { var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; var aligns = ['top', 'middle', 'bottom']; for (var i = 0; i < aligns.length; i++) { if (value.includes(aligns[i])) { return aligns[i]; } } var mapping = { 'baseline': 'middle', 'super': 'top', 'sub': 'bottom' }; return mapping[value]; }; exports.default = { workcellCreated: function workcellCreated(_ref) { var workcell = _ref.workcell, cellStyle = _ref.cellStyle; var verticalAlign = cellStyle.verticalAlign, textAlign = cellStyle.textAlign; workcell.alignment = _extends({}, workcell.alignment || {}, { vertical: getVerticalAlign(verticalAlign), horizontal: getHorizontalAlign(textAlign) }); } }; ================================================ FILE: es5/plugins/autoWidth.js ================================================ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = { workcellCreated: function workcellCreated(_ref) { var worksheet = _ref.worksheet, colRange = _ref.colRange, cell = _ref.cell, cellStyle = _ref.cellStyle; if (colRange.from === colRange.to && cellStyle.width !== 'auto') { worksheet.getColumn(colRange.from + 1).width = +cellStyle.width.split('px')[0] * this.options.widthRatio; } } }; ================================================ FILE: es5/plugins/fill.js ================================================ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _utils = require('../utils'); exports.default = { workcellCreated: function workcellCreated(_ref) { var workcell = _ref.workcell, cellStyle = _ref.cellStyle; var color = (0, _utils.argb)(cellStyle.backgroundColor); if (color === '00000000') { // background is transparent, equals none pattern fill workcell.fill = _extends({}, workcell.fill || {}, { type: 'pattern', pattern: 'none' }); } else { workcell.fill = _extends({}, workcell.fill || {}, { type: 'pattern', pattern: 'solid', fgColor: { argb: color } }); } } }; ================================================ FILE: es5/plugins/font.js ================================================ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _utils = require('../utils'); exports.default = { workcellCreated: function workcellCreated(_ref) { var workcell = _ref.workcell, cellStyle = _ref.cellStyle; var fontWeight = cellStyle.fontWeight; workcell.font = _extends({}, workcell.font || {}, { name: cellStyle.fontFamily, color: { argb: (0, _utils.argb)(cellStyle.color) }, bold: fontWeight === 'bold' || +fontWeight > 600 ? true : false }); } }; ================================================ FILE: es5/plugins/form.js ================================================ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = { workcellCreated: function workcellCreated(_ref) { var workcell = _ref.workcell, cell = _ref.cell; var child = cell.children[0]; if (child && ['INPUT', 'SELECT', 'TEXTAREA'].includes(child.tagName)) { workcell.value = child.value; } } }; ================================================ FILE: es5/plugins/hyperlink.js ================================================ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = { workcellCreated: function workcellCreated(_ref) { var workcell = _ref.workcell, cell = _ref.cell; var child = cell.children[0]; if (child && child.tagName === 'A') { workcell.value = { text: child.innerText, hyperlink: child.href }; } } }; ================================================ FILE: es5/plugins/index.js ================================================ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _font = require('./font'); var _font2 = _interopRequireDefault(_font); var _fill = require('./fill'); var _fill2 = _interopRequireDefault(_fill); var _form = require('./form'); var _form2 = _interopRequireDefault(_form); var _alignment = require('./alignment'); var _alignment2 = _interopRequireDefault(_alignment); var _hyperlink = require('./hyperlink'); var _hyperlink2 = _interopRequireDefault(_hyperlink); var _autoWidth = require('./autoWidth'); var _autoWidth2 = _interopRequireDefault(_autoWidth); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } exports.default = { fontPlugin: _font2.default, fillPlugin: _fill2.default, formPlugin: _form2.default, alignmentPlugin: _alignment2.default, hyperlinkPlugin: _hyperlink2.default, autoWidthPlugin: _autoWidth2.default }; ================================================ FILE: es5/table2excel.js ================================================ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _exceljs = require('exceljs/dist/es5/exceljs.browser'); var _exceljs2 = _interopRequireDefault(_exceljs); var _utils = require('./utils'); var _constants = require('./constants'); var _plugins = require('./plugins'); var _plugins2 = _interopRequireDefault(_plugins); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } var PLUGIN_FUNCS = ['workbookCreated', 'worksheetCreated', 'worksheetCompleted', 'workcellCreated']; var DEFAULT_WORKBOOK_OPTIONS = { views: [{ x: 0, y: 0, width: 10000, height: 20000, firstSheet: 0, activeTab: 1, visibility: 'visible' }] }; var DEFAULT_OPTIONS = { workbook: DEFAULT_WORKBOOK_OPTIONS, widthRatio: _constants.WIDTH_RATIO, plugins: [].concat(_toConsumableArray(Object.values(_plugins2.default))) }; var Table2Excel = function () { function Table2Excel() { var _this = this; var selector = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'table'; var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; _classCallCheck(this, Table2Excel); this.tables = Array.from(typeof selector === 'string' ? document.querySelectorAll(selector) : selector); this.options = Object.assign({}, DEFAULT_OPTIONS, options); this.plugins = {}; PLUGIN_FUNCS.forEach(function (funName) { _this.plugins[funName] = _this.options.plugins.filter(function (plugin) { return plugin[funName]; }).map(function (plugin) { return plugin[funName]; }); }); this.pluginContext = {}; } _createClass(Table2Excel, [{ key: '_invokePlugin', value: function _invokePlugin(func) { var _this2 = this; var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; this.pluginContext = Object.assign({}, this.pluginContext, context); this.plugins[func].forEach(function (handler) { return handler.call(_this2, _this2.pluginContext); }); } }, { key: 'toExcel', value: function toExcel() { var _this3 = this; var tables = this.tables, options = this.options; var workbook = new _exceljs2.default.Workbook(); // create workbook Object.assign(workbook, options); // workbookCreated plugins this._invokePlugin('workbookCreated', { workbook: workbook, tables: tables }); tables.forEach(function (table, index) { var worksheet = workbook.addWorksheet('Sheet ' + (index + 1)); // worksheetCreated plugins _this3._invokePlugin('worksheetCreated', { worksheet: worksheet, table: table }); _this3.toSheet(table, worksheet); // worksheetCompleted plugins _this3._invokePlugin('worksheetCompleted', { worksheet: worksheet, table: table }); }); return this.workbook = workbook; } }, { key: 'toSheet', value: function toSheet(table, worksheet) { var _this4 = this; // get total cols and rows var totalRows = table.rows.length; var totalCols = 0; if (table.rows.length > 0) { for (var i = 0; i < table.rows[0].cells.length; i++) { totalCols += table.rows[0].cells[i].colSpan; } } var cells = []; Array.from(table.rows).forEach(function (row) { Array.from(row.cells).forEach(function (cell) { cells.push({ rowRange: {}, colRange: {}, el: cell }); }); }); // create matrix var helperMatrix = []; for (var r = 0; r < totalRows; r++) { var row = []; for (var c = 0; c < totalCols; c++) { row.push({ cell: null }); } helperMatrix.push(row); } // mark matrix var cursor = 0; for (var _r = 0; _r < totalRows; _r++) { for (var _c = 0; _c < totalCols; _c++) { // skip if current matrix unit is already assigned if (helperMatrix[_r][_c].cell) { continue; } // assign cell to current matrix unit var cell = cells[cursor++]; var _cell$el = cell.el, rowSpan = _cell$el.rowSpan, colSpan = _cell$el.colSpan; cell.rowRange = { from: _r, to: _r }; cell.colRange = { from: _c, to: _c }; for (var y = _r; y < _r + rowSpan; y++) { for (var x = _c; x < _c + colSpan; x++) { helperMatrix[y][x].cell = cell; cell.colRange.to = x; cell.rowRange.to = y; } } } } // read matrix to sheet cells.forEach(function (cell) { var rowRange = cell.rowRange, colRange = cell.colRange, el = cell.el; var innerText = el.innerText; var workcell = (0, _utils.mergeCells)(worksheet, colRange.from, rowRange.from, colRange.to, rowRange.to); var cellStyle = getComputedStyle(el); workcell.value = innerText; // workcellCreated _this4._invokePlugin('workcellCreated', { workcell: workcell, cell: el, rowRange: rowRange, colRange: colRange, cellStyle: cellStyle }); }); } }, { key: 'export', value: function _export(fileName, ext) { if (!this.workbook) { this.toExcel(); } (0, _utils.saveAsExcel)(this.workbook, fileName, ext); } }]); return Table2Excel; }(); exports.default = Table2Excel; ================================================ FILE: es5/utils.js ================================================ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.argb = exports.mergeCells = exports.cellPosition = exports.columnIndex = exports.saveAsExcel = undefined; var _constants = require('./constants'); var _fileSaver = require('file-saver'); var saveAsExcel = exports.saveAsExcel = function saveAsExcel(workbook) { var filename = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'table'; var ext = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'xlsx'; var type = _constants.MIME_TYPES[ext]; if (!type) { console.error(ext + ' file extension is not supported'); return; } workbook.xlsx.writeBuffer().then(function (uint8) { (0, _fileSaver.saveAs)(new Blob([uint8.buffer], { type: type }), filename + '.' + ext); }); }; var letter = function letter(num) { var a = 'A'.charCodeAt(0); return String.fromCharCode(a + num - 1); }; /** * 0 => A * 25 => Z * 26 => AA */ var columnIndex = exports.columnIndex = function columnIndex(num) { var result = void 0; num = num + 1; if (num <= 26) { result = letter(num); } else { var mod = num % 26; var quotient = Math.floor(num / 26); if (mod === 0) { result = letter(quotient - 1) + letter(26); } else { result = letter(quotient) + letter(mod); } } return result; }; // x = 0, y = 0 => 'A1' // x = 0, y = 1 => 'A2' // x = 1, y = 0 => 'B1' var cellPosition = exports.cellPosition = function cellPosition(x, y) { return '' + columnIndex(x) + (y + 1); }; var mergeCells = exports.mergeCells = function mergeCells(sheet, x1, y1, x2, y2) { var fromCell = cellPosition(x1, y1); var toCell = cellPosition(x2, y2); sheet.mergeCells(fromCell, toCell); return sheet.getCell(fromCell); }; /** * convert rgb(0,0,0) rgba(0,0,0,0) to argb: FF00FF00 */ var argb = exports.argb = function argb(color) { var values = color.split('(')[1].split(')')[0].split(',').map(function (v, i) { return i === 3 ? v * 255 : v; }); if (values.length === 3) { values.push(255); } values.unshift(values.pop()); return values.map(function (v) { var s = parseInt(v).toString(16); return s.length === 1 ? '0' + s : s; }).join('').toUpperCase(); }; ================================================ FILE: package.json ================================================ { "name": "table2excel.js", "version": "1.0.0", "description": "", "main": "es5/index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build": "webpack --config webpack.core.config.js -p && webpack --config webpack.umd.config.js -p", "build:es5": "babel src --out-dir es5" }, "repository": { "type": "git", "url": "git+https://github.com/jackgit/table2excel.js.git" }, "keywords": [ "table", "js", "excel", "xlsx", "xls" ], "author": "ygjack414@hotmail.com", "license": "MIT", "bugs": { "url": "https://github.com/jackgit/table2excel.js/issues" }, "homepage": "https://github.com/jackgit/table2excel.js#readme", "dependencies": { "file-saver": "^1.3.3" }, "peerDependencies": { "exceljs": "^0.6.2" }, "devDependencies": { "babel-cli": "^6.26.0", "babel-core": "^6.26.0", "babel-loader": "^7.1.2", "babel-preset-es2015": "^6.24.1", "babel-preset-stage-1": "^6.24.1", "cross-env": "^5.2.0" } } ================================================ FILE: src/constants.js ================================================ export const MIME_TYPES = { xls: 'application/vnd.ms-excel', xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' } export const WIDTH_RATIO = .14 ================================================ FILE: src/index.js ================================================ import Table2Excel from './table2excel' import plugins from './plugins' import * as utils from './utils' Table2Excel.plugins = plugins Table2Excel.utils = utils export default Table2Excel ================================================ FILE: src/plugins/alignment.js ================================================ /** * '-webkit-right' -> 'right' * 'right' -> 'right' * etc... */ const getHorizontalAlign = (value = '') => { const aligns = ['right', 'left', 'center', 'justify'] for (let i = 0; i < aligns.length; i++) { if (value.includes(aligns[i])) { return aligns[i] } } } /** * 'baseline' -> 'middle' * 'text-top' -> 'top' * 'text-bottom' -> 'bottom' * 'sub' -> 'top' * 'super' -> 'bottom' */ const getVerticalAlign = (value = '') => { const aligns = ['top', 'middle', 'bottom'] for (let i = 0; i < aligns.length; i++) { if (value.includes(aligns[i])) { return aligns[i] } } const mapping = { 'baseline': 'middle', 'super': 'top', 'sub': 'bottom' } return mapping[value] } export default { workcellCreated ({ workcell, cellStyle }) { const { verticalAlign, textAlign } = cellStyle workcell.alignment = { ...(workcell.alignment || {}), ...({ vertical: getVerticalAlign(verticalAlign), horizontal: getHorizontalAlign(textAlign) }) } } } ================================================ FILE: src/plugins/autoWidth.js ================================================ export default { workcellCreated ({ worksheet, colRange, cell, cellStyle }) { if (colRange.from === colRange.to && cellStyle.width !== 'auto') { worksheet.getColumn(colRange.from + 1).width = (+cellStyle.width.split('px')[0]) * this.options.widthRatio } } } ================================================ FILE: src/plugins/fill.js ================================================ import { argb } from '../utils' export default { workcellCreated ({ workcell, cellStyle }) { const color = argb(cellStyle.backgroundColor) if (color === '00000000') { // background is transparent, equals none pattern fill workcell.fill = { ...(workcell.fill || {}), ...({ type: 'pattern', pattern: 'none' }) } } else { workcell.fill = { ...(workcell.fill || {}), ...({ type: 'pattern', pattern: 'solid', fgColor: { argb: color } }) } } } } ================================================ FILE: src/plugins/font.js ================================================ import { argb } from '../utils' export default { workcellCreated ({ workcell, cellStyle }) { const fontWeight = cellStyle.fontWeight workcell.font = { ...(workcell.font || {}), ...({ name: cellStyle.fontFamily, color: { argb: argb(cellStyle.color) }, bold: (fontWeight === 'bold' || +fontWeight > 600) ? true : false }) } } } ================================================ FILE: src/plugins/form.js ================================================ export default { workcellCreated ({ workcell, cell }) { const child = cell.children[0] if (child && ['INPUT', 'SELECT', 'TEXTAREA'].includes(child.tagName)) { workcell.value = child.value } } } ================================================ FILE: src/plugins/hyperlink.js ================================================ export default { workcellCreated ({ workcell, cell }) { const child = cell.children[0] if (child && child.tagName === 'A') { workcell.value = { text: child.innerText, hyperlink: child.href } } } } ================================================ FILE: src/plugins/index.js ================================================ import fontPlugin from './font' import fillPlugin from './fill' import formPlugin from './form' import alignmentPlugin from './alignment' import hyperlinkPlugin from './hyperlink' import autoWidthPlugin from './autoWidth' export default { fontPlugin, fillPlugin, formPlugin, alignmentPlugin, hyperlinkPlugin, autoWidthPlugin } ================================================ FILE: src/table2excel.js ================================================ import ExcelJS from 'exceljs/dist/es5/exceljs.browser' import { mergeCells, saveAsExcel } from './utils' import { WIDTH_RATIO } from './constants' import plugins from './plugins' const PLUGIN_FUNCS = ['workbookCreated', 'worksheetCreated', 'worksheetCompleted', 'workcellCreated'] const DEFAULT_WORKBOOK_OPTIONS = { views: [{ x: 0, y: 0, width: 10000, height: 20000, firstSheet: 0, activeTab: 1, visibility: 'visible' }] } const DEFAULT_OPTIONS = { workbook: DEFAULT_WORKBOOK_OPTIONS, widthRatio: WIDTH_RATIO, plugins: [...Object.values(plugins)] } export default class Table2Excel { constructor (selector = 'table', options = {}) { this.tables = Array.from( typeof selector === 'string' ? document.querySelectorAll(selector) : selector ) this.options = Object.assign({}, DEFAULT_OPTIONS, options) this.plugins = {} PLUGIN_FUNCS.forEach(funName => { this.plugins[funName] = this.options.plugins.filter(plugin => plugin[funName]).map(plugin => plugin[funName]) }) this.pluginContext = {} } _invokePlugin (func, context = {}) { this.pluginContext = Object.assign({}, this.pluginContext, context) this.plugins[func].forEach(handler => handler.call(this, this.pluginContext)) } toExcel () { const { tables, options } = this const workbook = new ExcelJS.Workbook() // create workbook Object.assign(workbook, options) // workbookCreated plugins this._invokePlugin('workbookCreated', { workbook, tables }) tables.forEach((table, index) => { const worksheet = workbook.addWorksheet(`Sheet ${index + 1}`) // worksheetCreated plugins this._invokePlugin('worksheetCreated', { worksheet, table }) this.toSheet(table, worksheet) // worksheetCompleted plugins this._invokePlugin('worksheetCompleted', { worksheet, table }) }) return this.workbook = workbook } toSheet (table, worksheet) { // get total cols and rows const totalRows = table.rows.length let totalCols = 0 if (table.rows.length > 0) { for (let i = 0; i < table.rows[0].cells.length; i++) { totalCols += table.rows[0].cells[i].colSpan } } const cells = [] Array.from(table.rows).forEach(row => { Array.from(row.cells).forEach(cell => { cells.push({ rowRange: {}, colRange: {}, el: cell }) }) }) // create matrix const helperMatrix = [] for (let r = 0; r < totalRows; r++) { const row = [] for (let c = 0; c < totalCols; c++) { row.push({ cell: null }) } helperMatrix.push(row) } // mark matrix let cursor = 0 for (let r = 0; r < totalRows; r++) { for (let c = 0; c < totalCols; c++) { // skip if current matrix unit is already assigned if (helperMatrix[r][c].cell) { continue } // assign cell to current matrix unit const cell = cells[cursor++] const { rowSpan, colSpan } = cell.el cell.rowRange = { from: r, to: r } cell.colRange = { from: c, to: c } for (let y = r; y < r + rowSpan; y++) { for (let x = c; x < c + colSpan; x++) { helperMatrix[y][x].cell = cell cell.colRange.to = x cell.rowRange.to = y } } } } // read matrix to sheet cells.forEach(cell => { const { rowRange, colRange, el } = cell const { innerText } = el const workcell = mergeCells(worksheet, colRange.from, rowRange.from, colRange.to, rowRange.to) const cellStyle = getComputedStyle(el) workcell.value = innerText // workcellCreated this._invokePlugin('workcellCreated', { workcell, cell: el, rowRange, colRange, cellStyle }) }) } export (fileName, ext) { if (!this.workbook) { this.toExcel() } saveAsExcel(this.workbook, fileName, ext) } } ================================================ FILE: src/utils.js ================================================ import { MIME_TYPES } from './constants' import { saveAs } from 'file-saver' export const saveAsExcel = (workbook, filename = 'table', ext = 'xlsx') => { const type = MIME_TYPES[ext] if (!type) { console.error(`${ext} file extension is not supported`) return } workbook.xlsx.writeBuffer().then(uint8 => { saveAs( new Blob([uint8.buffer], { type }), `${filename}.${ext}` ) }) } const letter = num => { const a = 'A'.charCodeAt(0) return String.fromCharCode(a + num - 1) } /** * 0 => A * 25 => Z * 26 => AA */ export const columnIndex = num => { let result num = num + 1 if (num <= 26) { result = letter(num) } else { const mod = num % 26 const quotient = Math.floor(num / 26) if (mod === 0) { result = letter(quotient - 1) + letter(26) } else { result = letter(quotient) + letter(mod) } } return result } // x = 0, y = 0 => 'A1' // x = 0, y = 1 => 'A2' // x = 1, y = 0 => 'B1' export const cellPosition = (x, y) => { return `${columnIndex(x)}${y + 1}` } export const mergeCells = (sheet, x1, y1, x2, y2) => { const fromCell = cellPosition(x1, y1) const toCell = cellPosition(x2, y2) sheet.mergeCells(fromCell, toCell) return sheet.getCell(fromCell) } /** * convert rgb(0,0,0) rgba(0,0,0,0) to argb: FF00FF00 */ export const argb = color => { const values = color .split('(')[1].split(')')[0].split(',') .map((v, i) => i === 3 ? v * 255 : v) if (values.length === 3) { values.push(255) } values.unshift(values.pop()) return values.map(v => { const s = parseInt(v).toString(16) return s.length === 1 ? `0${s}` : s }).join('').toUpperCase() } ================================================ FILE: webpack.core.config.js ================================================ module.exports = { entry: './src/index.js', output: { filename: './dist/table2excel.core.js', library: 'Table2Excel', libraryTarget: 'umd', libraryExport: 'default' }, module: { rules: [ { test: /\.js$/, use: [ 'babel-loader', ], exclude: /node_modules/ } ] }, externals: { 'exceljs/dist/es5/exceljs.browser': 'ExcelJS' }, node: { fs: 'empty' } }; ================================================ FILE: webpack.umd.config.js ================================================ module.exports = { entry: './src/index.js', output: { filename: './dist/table2excel.min.js', library: 'Table2Excel', libraryTarget: 'umd', libraryExport: 'default' }, module: { rules: [ { test: /\.js$/, use: [ 'babel-loader', ], exclude: /node_modules/ } ] }, node: { fs: 'empty' } };