forked from functionscope/Node-Excel-Export
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.js
More file actions
86 lines (70 loc) · 1.82 KB
/
helpers.js
File metadata and controls
86 lines (70 loc) · 1.82 KB
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
exports.startTag = function (obj, tagName, closed) {
var result = '<' + tagName;
for (var p in obj) {
result += ' ' + p + '=' + obj[p];
}
if (!closed) {
result += '>';
} else {
result += '/>';
}
return result;
};
exports.endTag = function (tagName) {
return `</${tagName}>`;
};
exports.addNumberCell = 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>`;
}
};
exports.addDateCell = 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>`;
}
};
exports.addBoolCell = 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>`;
};
exports.addStringCell = function (sheet, cellRef, value, styleIndex) {
styleIndex = styleIndex || 0;
if (value === null) {
return '';
}
if (typeof value === 'string') {
value = value.replace(/&/g, '&').replace(/'/g, ''').replace(/>/g, '>').replace(/</g, '<');
}
return `<x:c r="${cellRef}" s="${styleIndex}" t="inlineStr"><x:is><x:t>${value}</x:t></x:is></x:c>`;
};
exports.getColumnLetter = function (col) {
if (col <= 0) {
throw 'col must be more than 0';
}
var 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());
};