-
Notifications
You must be signed in to change notification settings - Fork 13
/
typings.d.ts
273 lines (271 loc) · 6.19 KB
/
typings.d.ts
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
declare module '*.css';
declare module '*.less';
declare module 'better-xlsx' {
export class File {
/**
* Add a new Sheet, with the provided name, to a File
* @param {String} name Name of the Sheet
* @return {Sheet}
*/
addSheet: (name: string) => Sheet;
/**
* Save the File to an xlsx file.
* @param {String} [type='nodebuffer'] For Node.js use `nodebuffer` and browser use `blob` or `base64`.
* @param {Boolean} [compress=false] For file compression.
* @return {Promise|stream} For Node.js return `stream` and browser return Promise.
*/
saveAs: (type: string, compress: boolean) => Promise<any>;
}
export class Sheet {
rows: Row[];
cols: Col[];
maxRow: number;
maxCol: number;
/**
* Create a Row and add it into the Sheet.
* @return {Row}
*/
addRow: () => Row;
/**
* Get Col of the sheet with index and create cols when `index > maxCol`.
* @param {Number} idx Index of the Col [from 0].
* @return {Col}
*/
col: (idx: number) => Col;
/**
* Get Row of the sheet with index and create rows when `index > maxRow`.
* @param {Number} idx Index of the Row [from 0].
* @return {Row}
*/
row: (idx: number) => Row;
/**
* Get Cell of the sheet with `(row, col)` and create cell when out of range.
* @param {Number} row
* @param {Number} col
* @return {Cell}
*/
cell: (row: number, col: number) => Cell;
/**
* Set columns width from `startcol` to `endcol`.
* @param {Number} startcol
* @param {Number} endcol
* @param {Number} width
*/
setColWidth: (startcol: number, endcol: number, width: number) => void;
}
export class Row {
cells: Cell[];
/**
* Set height of the Row with `cm` unit.
* @param {Number} ht Height with `cm` unit
*/
setHeightCM: (ht: number) => void;
/**
* Create a cell and add it into the Row.
* @return {Cell}
*/
addCell: () => Cell;
}
export class Col {
width: number;
numFmt: string;
style: Style;
setType: (cellType: string) => void;
}
export class Cell {
value: string | number | Date | boolean;
hMerge: number;
vMerge: number;
cellType: ICellType;
numFmt: INumFmt;
formula: string;
style: Style;
/**
* Set cell value with String type.
* @param {String} v
*/
setString: (v: string) => void;
/**
* Set cell value with Date type.
* @param {Date} v
*/
setDate: (v: Date) => void;
/**
* Set cell value with DateTime type.
* @param {Date} v
*/
setDateTime: (v: Date) => void;
/**
* Set cell value with Number type.
* @param {Number} v
*/
setNumber: (v: number) => void;
/**
* Set cell value with Boolean type.
* @param {Boolean} v
*/
setBool: (v: boolean) => void;
/**
* Set cell formula.
* @param {String} f - Formula like `B2*C2-D2`.
*/
setFormula: (f: string) => void;
}
export class Style {
border: {
left: string;
leftColor: string;
right: string;
rightColor: string;
top: string;
topColor: string;
bottom: string;
bottomColor: string;
};
fill: {
patternType: string;
fgColor: string;
bgColor: string;
};
font: {
size: number;
name: string;
family: number;
charset: number;
color: string;
bold: boolean;
i: boolean;
u: boolean;
};
align: {
h: IHorizontal;
indent: number;
shrinkToFit: boolean;
textRotation: number;
v: IVertical;
wrapText: boolean;
};
applyBorder: boolean;
applyFill: boolean;
applyFont: boolean;
applyAlignment: boolean;
}
}
// 表格列属性
interface IExcelColumn {
title: string;
dataIndex: string;
width?: number;
children?: IExcelColumn[];
align?: 'left' | 'right' | 'center';
colSpan?: number;
render?: (text: any, record: any, index: number) => React.ReactNode | object;
excelRender?: (
text: any,
record: any,
index: number,
) => React.ReactNode | object;
__style__?: IStyle;
__numFmt__?: INumFmt;
__cellType__?: ICellType;
// 自动生成的私有属性,不要传入
__hMerge__?: number;
__vMerge__?: number;
__x__?: number;
}
// 单元格属性
interface ICellProps {
value: string;
hMerge?: number;
vMerge?: number;
cellType?: ICellType;
numFmt?: INumFmt;
formula?: string;
style?: IStyle;
}
interface ITbodyConfig {
// 字符串能转化成数字就转化成数字
str2num?: boolean;
// 还是放在列配置里比较好
// 数值精度
// precision?: number;
// 是否转化成百分比
// toPercent?: boolean;
}
interface IDataSource extends Object {
__style__?: IStyle;
__numFmt__?: INumFmt;
__cellType__?: ICellType;
[key: string]: any;
}
type IStyle = {
height?: number;
width?: number;
border?: boolean;
borderColor?: string;
background?: string;
fontSize?: number;
fontName?: string;
color?: string;
bold?: boolean;
i?: boolean;
u?: boolean;
h?: IHorizontal;
indent?: number;
shrinkToFit?: boolean;
textRotation?: number;
v?: IVertical;
wrapText?: boolean;
};
type IHorizontal = 'general' | 'center' | 'left' | 'right';
type IVertical = 'general' | 'top' | 'bottom' | 'center';
type ICellType =
| 'TypeString'
| 'TypeBool'
| 'TypeNumeric'
| 'TypeDate'
| 'TypeFormula'
| 'TypeError'
| 'TypeGeneral';
type INumFmt =
| 'general'
| '0'
| '0.0'
| '0.00'
| '0.000'
| '0.0000'
| '#,##0'
| '#,##0.0'
| '#,##0.00'
| '#,##0.000'
| '#,##0.0000'
| '0%'
| '0.0%'
| '0.00%'
| '0.000%'
| '0.0000%'
| '0.00e+00'
| '# ?/?'
| '# ??/??'
| 'mm-dd-yy'
| 'd-mmm-yy'
| 'd-mmm'
| 'mmm-yy'
| 'h:mm am/pm'
| 'h:mm:ss am/pm'
| 'h:mm'
| 'h:mm:ss'
| 'm/d/yy h:mm'
| '#,##0 ;(#,##0)'
| '#,##0 ;[red](#,##0)'
| '#,##0.00;(#,##0.00)'
| '#,##0.00;[red](#,##0.00)'
| '_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)'
| '_("$"* #,##0_);_("$* (#,##0);_("$"* "-"_);_(@_)'
| '_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)'
| '_("$"* #,##0.00_);_("$"* (#,##0.00);_("$"* "-"??_);_(@_)'
| 'mm:ss'
| '[h]:mm:ss'
| 'mmss.0'
| '##0.0e+0'
| '@';