forked from functionscope/Node-Excel-Export
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
195 lines (176 loc) · 14.5 KB
/
index.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
require('node-zip');
var fs = require('fs');
Date.prototype.getJulian = function() {
return Math.floor((this / 86400000) -
(this.getTimezoneOffset()/1440) + 2440587.5);
};
Date.prototype.oaDate = function() {
return (this - new Date(Date.UTC(1899,11,30))) / (24 * 60 * 60 * 1000);
};
var templateXLSX = "UEsDBBQAAAAIABN7eUK9Z10uOQEAADUEAAATAAAAW0NvbnRlbnRfVHlwZXNdLnhtbK2US04DMQyGrzLKFk1SWCCEOu0C2EIluECUeDpR81LslvZsLDgSV8CdQQVViALtJlFi+//+PN9eXsfTdfDVCgq6FBtxLkeigmiSdXHeiCW19ZWYTsZPmwxYcWrERnRE+VopNB0EjTJliBxpUwmaeFjmKmuz0HNQF6PRpTIpEkSqaashJuNbaPXSU3W35ukBy+WiuhnytqhG6Jy9M5o4rFbR7kHq1LbOgE1mGbhEYi6gLXYAFLzsexm0i2e9sPqWWcDj36Afq5Jc2edg5zL+hMgYrMn/g5hUoM6Fo4UcfGIe+KyKs1DNdKF7HVhR8T7MOBMVa8tj9xK2/i3Y38LXXmGnC9hHKnxp8GgD+4f5RfugEdp4OL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AAywoAAHhsL3RoZW1lL1BLAQIUABQAAAAIABN7eUJ1sZFetwUAALsbAAASAAAAAAAAAAEAAAAAAPIKAAB4bC90aGVtZS90aGVtZS54bWxQSwECFAAUAAAACAATe3lCid5wRgIBAAC7AQAADwAAAAAAAAABAAAAAADZEAAAeGwvd29ya2Jvb2sueG1sUEsBAhQAFAAAAAAAxYV5QgAAAAAAAAAAAAAAAA4AAAAAAAAAAAAQAAAACBIAAHhsL3dvcmtzaGVldHMvUEsBAhQAFAAAAAgANoh5QsFI9YjaAQAAiQMAABcAAAAAAAAAAQAgAAAANBIAAHhsL3dvcmtzaGVldHMvc2hlZXQueG1sUEsFBgAAAAAQABAARwQAAEMUAAAAAA==";
var sheetFront = '<?xml version="1.0" encoding="utf-8"?><x:worksheet xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x14ac" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"><x:sheetPr><x:outlinePr summaryBelow="1" summaryRight="1" /></x:sheetPr><x:sheetViews><x:sheetView tabSelected="0" workbookViewId="0" /></x:sheetViews><x:sheetFormatPr defaultRowHeight="15" />';
var sheetBack = '<x:printOptions horizontalCentered="0" verticalCentered="0" headings="0" gridLines="0" /><x:pageMargins left="0.75" right="0.75" top="0.75" bottom="0.5" header="0.5" footer="0.75" /><x:pageSetup paperSize="1" scale="100" pageOrder="downThenOver" orientation="default" blackAndWhite="0" draft="0" cellComments="none" errors="displayed" /><x:headerFooter /><x:tableParts count="0" /></x:worksheet>';
var sharedStringsFront = '<?xml version="1.0" encoding="UTF-8"?><x:sst xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main" uniqueCount="$count" count="$count">';
var sharedStringsBack = '</x:sst>';
var shareStrings, convertedShareStrings;
exports.executeAsync = function(config, callBack){
return process.nextTick(function(){
var r = exports.execute(config);
callBack(r);
});
};
exports.execute = function(config){
var cols = config.cols,
data = config.rows,
colsLength = cols.length,
xlsx = new JSZip(templateXLSX, { base64: true, checkCRC32: false }),
sheet = xlsx.file("xl/worksheets/sheet.xml"),
sharedStringsXml = xlsx.file("xl/sharedStrings.xml"),
rows = "",
row ="",
colsWidth = "",
styleIndex,
k;
if (config.stylesXmlFile){
var path = config.stylesXmlFile;
var styles = null;
styles = fs.readFileSync(path, 'utf8');
if (styles){
xlsx.file("xl/styles.xml", styles);
}
}
shareStrings = new Array();
convertedShareStrings = "";
//first row for column caption
row = '<x:row r="1" spans="1:'+ colsLength + '">';
var colStyleIndex;
for (k=0; k < colsLength; k++)
{
colStyleIndex = cols[k].captionStyleIndex || 0;
row += addStringCol(getColumnLetter(k+1)+1, cols[k].caption, colStyleIndex);
if (cols[k].width){
colsWidth += '<col customWidth = "1" width="' + cols[k].width + '" max = "' + (k+1) +'" min="' + (k+1) +'"/>';
}
}
row += '</x:row>';
rows += row;
//fill in data
var i, j, r, cellData, currRow, cellType,
dataLength = data.length;
for (i=0;i<dataLength;i++)
{
r = data[i], currRow = i+2;
row = '<x:row r="' + currRow +'" spans="1:'+ colsLength + '">';
for (j=0; j < colsLength; j++)
{
styleIndex = null;
cellData = r[j];
cellType = cols[j].type;
if (typeof cols[j].beforeCellWrite === 'function'){
var e ={rowNum: currRow, styleIndex: null, cellType: cellType};
cellData = cols[j].beforeCellWrite(r, cellData, e);
styleIndex = e.styleIndex || styleIndex;
cellType = e.cellType;
delete e;
}
switch(cellType)
{
case 'number':
row += addNumberCol(getColumnLetter(j+1)+currRow, cellData, styleIndex);
break;
case 'date':
row += addDateCol(getColumnLetter(j+1)+currRow, cellData, styleIndex);
break;
case 'bool':
row += addBoolCol(getColumnLetter(j+1)+currRow, cellData, styleIndex);
break;
default:
row += addStringCol(getColumnLetter(j+1)+currRow, cellData, styleIndex);
}
}
row += '</x:row>';
rows += row;
}
if (colsWidth !== "")
sheetFront += '<cols>'+colsWidth+'</cols>';
xlsx.file(sheet.name, sheetFront + '<x:sheetData>' + rows + '</x:sheetData>' + sheetBack);
if (shareStrings.length >0)
{
sharedStringsFront = sharedStringsFront.replace(/\$count/g, shareStrings.length);
xlsx.file(sharedStringsXml.name, (sharedStringsFront + convertedShareStrings + sharedStringsBack));
}
var results = xlsx.generate({ base64: false, compression: "DEFLATE" });
delete xlsx;
delete shareStrings;
return results;
};
var startTag = function (obj, tagName, closed){
var result = "<" + tagName, p;
for (p in obj){
result += " " + p + "=" + obj[p];
}
if (!closed)
result += ">";
else
result += "/>";
return result;
};
var endTag = function(tagName){
return "</" + tagName + ">";
};
var addNumberCol = function(cellRef, value, styleIndex){
styleIndex = styleIndex || 0;
if (value===null)
return "";
else
return '<x:c r="'+cellRef+'" s="'+ styleIndex +'" t="n"><x:v>'+value+'</x:v></x:c>';
};
var addDateCol = function(cellRef, value, styleIndex){
styleIndex = styleIndex || 1;
if (value===null)
return "";
else
return '<x:c r="'+cellRef+'" s="'+ styleIndex +'" t="n"><x:v>'+value+'</x:v></x:c>';
};
var addBoolCol = function(cellRef, value, styleIndex){
styleIndex = styleIndex || 0;
if (value===null)
return "";
if (value){
value = 1;
} else
value = 0;
return '<x:c r="'+cellRef+'" s="'+ styleIndex + '" t="b"><x:v>'+value+'</x:v></x:c>';
};
var addStringCol = function(cellRef, value, styleIndex){
styleIndex = styleIndex || 0;
if (value===null)
return "";
if (typeof value ==='string'){
value = value.replace(/&/g, "&").replace(/'/g, "'").replace(/>/g, ">").replace(/</g, "<");
}
var i = shareStrings.indexOf(value);
if ( i< 0){
i = shareStrings.push(value) -1;
convertedShareStrings = convertedShareStrings+ "<x:si><x:t>"+value+"</x:t></x:si>";
}
return '<x:c r="'+cellRef+'" s="'+ styleIndex + '" t="s"><x:v>'+i+'</x:v></x:c>';
};
var getColumnLetter = function(col){
if (col <= 0)
throw "col must be more than 0";
var array = new Array();
while (col > 0)
{
var remainder = col % 26;
col /= 26;
col = Math.floor(col);
if(remainder ===0)
{
remainder = 26;
col--;
}
array.push(64 + remainder);
}
return String.fromCharCode.apply(null, array.reverse());
};