1
1
function write_UInt32LE ( x /*:number*/ , o ) {
2
- if ( ! o ) o = new_buf ( 4 ) ;
2
+ if ( ! o ) o = new_buf ( 4 ) ;
3
3
o . write_shift ( 4 , x ) ;
4
4
return o ;
5
5
}
@@ -10,9 +10,9 @@ function parse_XLWideString(data/*::, length*/)/*:string*/ {
10
10
return cchCharacters === 0 ? "" : data . read_shift ( cchCharacters , 'dbcs' ) ;
11
11
}
12
12
function write_XLWideString ( data /*:string*/ , o ) {
13
- var _null = false ; if ( o == null ) { _null = true ; o = new_buf ( 4 + 2 * data . length ) ; }
13
+ var _null = false ; if ( o == null ) { _null = true ; o = new_buf ( 4 + 2 * data . length ) ; }
14
14
o . write_shift ( 4 , data . length ) ;
15
- if ( data . length > 0 ) o . write_shift ( 0 , data , 'dbcs' ) ;
15
+ if ( data . length > 0 ) o . write_shift ( 0 , data , 'dbcs' ) ;
16
16
return _null ? o . slice ( 0 , o . l ) : o ;
17
17
}
18
18
@@ -27,7 +27,7 @@ function parse_StrRun(data) {
27
27
return { ich : data . read_shift ( 2 ) , ifnt : data . read_shift ( 2 ) } ;
28
28
}
29
29
function write_StrRun ( run , o ) {
30
- if ( ! o ) o = new_buf ( 4 ) ;
30
+ if ( ! o ) o = new_buf ( 4 ) ;
31
31
o . write_shift ( 2 , run . ich || 0 ) ;
32
32
o . write_shift ( 2 , run . ifnt || 0 ) ;
33
33
return o ;
@@ -40,13 +40,13 @@ function parse_RichStr(data, length/*:number*/)/*:XLString*/ {
40
40
var str = parse_XLWideString ( data ) ;
41
41
var rgsStrRun = [ ] ;
42
42
var z = ( { t : str , h : str } /*:any*/ ) ;
43
- if ( ( flags & 1 ) !== 0 ) { /* fRichStr */
43
+ if ( ( flags & 1 ) !== 0 ) { /* fRichStr */
44
44
/* TODO: formatted string */
45
45
var dwSizeStrRun = data . read_shift ( 4 ) ;
46
- for ( var i = 0 ; i != dwSizeStrRun ; ++ i ) rgsStrRun . push ( parse_StrRun ( data ) ) ;
46
+ for ( var i = 0 ; i != dwSizeStrRun ; ++ i ) rgsStrRun . push ( parse_StrRun ( data ) ) ;
47
47
z . r = rgsStrRun ;
48
48
}
49
- else z . r = [ { ich :0 , ifnt :0 } ] ;
49
+ else z . r = [ { ich : 0 , ifnt : 0 } ] ;
50
50
//if((flags & 2) !== 0) { /* fExtStr */
51
51
// /* TODO: phonetic string */
52
52
//}
@@ -55,33 +55,33 @@ function parse_RichStr(data, length/*:number*/)/*:XLString*/ {
55
55
}
56
56
function write_RichStr ( str /*:XLString*/ , o /*:?Block*/ ) /*:Block*/ {
57
57
/* TODO: formatted string */
58
- var _null = false ; if ( o == null ) { _null = true ; o = new_buf ( 15 + 4 * str . t . length ) ; }
59
- o . write_shift ( 1 , 0 ) ;
58
+ var _null = false ; if ( o == null ) { _null = true ; o = new_buf ( 15 + 4 * str . t . length ) ; }
59
+ o . write_shift ( 1 , 0 ) ;
60
60
write_XLWideString ( str . t , o ) ;
61
61
return _null ? o . slice ( 0 , o . l ) : o ;
62
62
}
63
63
/* [MS-XLSB] 2.4.328 BrtCommentText (RichStr w/1 run) */
64
64
var parse_BrtCommentText = parse_RichStr ;
65
65
function write_BrtCommentText ( str /*:XLString*/ , o /*:?Block*/ ) /*:Block*/ {
66
66
/* TODO: formatted string */
67
- var _null = false ; if ( o == null ) { _null = true ; o = new_buf ( 23 + 4 * str . t . length ) ; }
68
- o . write_shift ( 1 , 1 ) ;
67
+ var _null = false ; if ( o == null ) { _null = true ; o = new_buf ( 23 + 4 * str . t . length ) ; }
68
+ o . write_shift ( 1 , 1 ) ;
69
69
write_XLWideString ( str . t , o ) ;
70
- o . write_shift ( 4 , 1 ) ;
71
- write_StrRun ( { ich :0 , ifnt :0 } , o ) ;
70
+ o . write_shift ( 4 , 1 ) ;
71
+ write_StrRun ( { ich : 0 , ifnt : 0 } , o ) ;
72
72
return _null ? o . slice ( 0 , o . l ) : o ;
73
73
}
74
74
75
75
/* [MS-XLSB] 2.5.9 */
76
76
function parse_XLSBCell ( data ) /*:any*/ {
77
77
var col = data . read_shift ( 4 ) ;
78
78
var iStyleRef = data . read_shift ( 2 ) ;
79
- iStyleRef += data . read_shift ( 1 ) << 16 ;
79
+ iStyleRef += data . read_shift ( 1 ) << 16 ;
80
80
data . l ++ ; //var fPhShow = data.read_shift(1);
81
- return { c :col , iStyleRef : iStyleRef } ;
81
+ return { c : col , iStyleRef : iStyleRef } ;
82
82
}
83
83
function write_XLSBCell ( cell /*:any*/ , o /*:?Block*/ ) {
84
- if ( o == null ) o = new_buf ( 8 ) ;
84
+ if ( o == null ) o = new_buf ( 8 ) ;
85
85
o . write_shift ( - 4 , cell . c ) ;
86
86
o . write_shift ( 3 , cell . iStyleRef || cell . s ) ;
87
87
o . write_shift ( 1 , 0 ) ; /* fPhShow */
@@ -99,9 +99,9 @@ function parse_XLNullableWideString(data/*::, length*/)/*:string*/ {
99
99
return cchCharacters === 0 || cchCharacters === 0xFFFFFFFF ? "" : data . read_shift ( cchCharacters , 'dbcs' ) ;
100
100
}
101
101
function write_XLNullableWideString ( data /*:string*/ , o ) {
102
- var _null = false ; if ( o == null ) { _null = true ; o = new_buf ( 127 ) ; }
102
+ var _null = false ; if ( o == null ) { _null = true ; o = new_buf ( 127 ) ; }
103
103
o . write_shift ( 4 , data . length > 0 ? data . length : 0xFFFFFFFF ) ;
104
- if ( data . length > 0 ) o . write_shift ( 0 , data , 'dbcs' ) ;
104
+ if ( data . length > 0 ) o . write_shift ( 0 , data , 'dbcs' ) ;
105
105
return _null ? o . slice ( 0 , o . l ) : o ;
106
106
}
107
107
@@ -116,34 +116,34 @@ var write_RelID = write_XLNullableWideString;
116
116
117
117
/* [MS-XLS] 2.5.217 ; [MS-XLSB] 2.5.122 */
118
118
function parse_RkNumber ( data ) /*:number*/ {
119
- var b = data . slice ( data . l , data . l + 4 ) ;
119
+ var b = data . slice ( data . l , data . l + 4 ) ;
120
120
var fX100 = ( b [ 0 ] & 1 ) , fInt = ( b [ 0 ] & 2 ) ;
121
- data . l += 4 ;
121
+ data . l += 4 ;
122
122
b [ 0 ] &= 0xFC ; // b[0] &= ~3;
123
- var RK = fInt === 0 ? __double ( [ 0 , 0 , 0 , 0 , b [ 0 ] , b [ 1 ] , b [ 2 ] , b [ 3 ] ] , 0 ) : __readInt32LE ( b , 0 ) >> 2 ;
124
- return fX100 ? ( RK / 100 ) : RK ;
123
+ var RK = fInt === 0 ? __double ( [ 0 , 0 , 0 , 0 , b [ 0 ] , b [ 1 ] , b [ 2 ] , b [ 3 ] ] , 0 ) : __readInt32LE ( b , 0 ) >> 2 ;
124
+ return fX100 ? ( RK / 100 ) : RK ;
125
125
}
126
126
function write_RkNumber ( data /*:number*/ , o ) {
127
- if ( o == null ) o = new_buf ( 4 ) ;
127
+ if ( o == null ) o = new_buf ( 4 ) ;
128
128
var fX100 = 0 , fInt = 0 , d100 = data * 100 ;
129
- if ( ( data == ( data | 0 ) ) && ( data >= - ( 1 << 29 ) ) && ( data < ( 1 << 29 ) ) ) { fInt = 1 ; }
130
- else if ( ( d100 == ( d100 | 0 ) ) && ( d100 >= - ( 1 << 29 ) ) && ( d100 < ( 1 << 29 ) ) ) { fInt = 1 ; fX100 = 1 ; }
131
- if ( fInt ) o . write_shift ( - 4 , ( ( fX100 ? d100 : data ) << 2 ) + ( fX100 + 2 ) ) ;
129
+ if ( ( data == ( data | 0 ) ) && ( data >= - ( 1 << 29 ) ) && ( data < ( 1 << 29 ) ) ) { fInt = 1 ; }
130
+ else if ( ( d100 == ( d100 | 0 ) ) && ( d100 >= - ( 1 << 29 ) ) && ( d100 < ( 1 << 29 ) ) ) { fInt = 1 ; fX100 = 1 ; }
131
+ if ( fInt ) o . write_shift ( - 4 , ( ( fX100 ? d100 : data ) << 2 ) + ( fX100 + 2 ) ) ;
132
132
else throw new Error ( "unsupported RkNumber " + data ) ; // TODO
133
133
}
134
134
135
135
136
136
/* [MS-XLSB] 2.5.117 RfX */
137
137
function parse_RfX ( data /*::, length*/ ) /*:Range*/ {
138
- var cell /*:Range*/ = ( { s : { } , e : { } } /*:any*/ ) ;
138
+ var cell /*:Range*/ = ( { s : { } , e : { } } /*:any*/ ) ;
139
139
cell . s . r = data . read_shift ( 4 ) ;
140
140
cell . e . r = data . read_shift ( 4 ) ;
141
141
cell . s . c = data . read_shift ( 4 ) ;
142
142
cell . e . c = data . read_shift ( 4 ) ;
143
143
return cell ;
144
144
}
145
145
function write_RfX ( r /*:Range*/ , o ) {
146
- if ( ! o ) o = new_buf ( 16 ) ;
146
+ if ( ! o ) o = new_buf ( 16 ) ;
147
147
o . write_shift ( 4 , r . s . r ) ;
148
148
o . write_shift ( 4 , r . e . r ) ;
149
149
o . write_shift ( 4 , r . s . c ) ;
@@ -180,20 +180,6 @@ var write_UncheckedRfX = write_RfX;
180
180
function parse_Xnum ( data /*::, length*/ ) { return data . read_shift ( 8 , 'f' ) ; }
181
181
function write_Xnum ( data , o ) { return ( o || new_buf ( 8 ) ) . write_shift ( 8 , data , 'f' ) ; }
182
182
183
- /* [MS-XLSB] 2.5.97.2 */
184
- var BErr = {
185
- /*::[*/ 0x00 /*::]*/ : "#NULL!" ,
186
- /*::[*/ 0x07 /*::]*/ : "#DIV/0!" ,
187
- /*::[*/ 0x0F /*::]*/ : "#VALUE!" ,
188
- /*::[*/ 0x17 /*::]*/ : "#REF!" ,
189
- /*::[*/ 0x1D /*::]*/ : "#NAME?" ,
190
- /*::[*/ 0x24 /*::]*/ : "#NUM!" ,
191
- /*::[*/ 0x2A /*::]*/ : "#N/A" ,
192
- /*::[*/ 0x2B /*::]*/ : "#GETTING_DATA" ,
193
- /*::[*/ 0xFF /*::]*/ : "#WTF?"
194
- } ;
195
- var RBErr = evert_num ( BErr ) ;
196
-
197
183
/* [MS-XLSB] 2.4.324 BrtColor */
198
184
function parse_BrtColor ( data /*::, length*/ ) {
199
185
var out = { } ;
@@ -209,51 +195,51 @@ function parse_BrtColor(data/*::, length*/) {
209
195
var bB = data . read_shift ( 1 ) ;
210
196
data . l ++ ; //var bAlpha = data.read_shift(1);
211
197
212
- switch ( xColorType ) {
198
+ switch ( xColorType ) {
213
199
case 0 : out . auto = 1 ; break ;
214
200
case 1 :
215
201
out . index = index ;
216
202
var icv = XLSIcv [ index ] ;
217
203
/* automatic pseudo index 81 */
218
- if ( icv ) out . rgb = rgb2Hex ( icv ) ;
204
+ if ( icv ) out . rgb = rgb2Hex ( icv ) ;
219
205
break ;
220
206
case 2 :
221
207
/* if(!fValidRGB) throw new Error("invalid"); */
222
208
out . rgb = rgb2Hex ( [ bR , bG , bB ] ) ;
223
209
break ;
224
210
case 3 : out . theme = index ; break ;
225
211
}
226
- if ( nTS != 0 ) out . tint = nTS > 0 ? nTS / 32767 : nTS / 32768 ;
212
+ if ( nTS != 0 ) out . tint = nTS > 0 ? nTS / 32767 : nTS / 32768 ;
227
213
228
214
return out ;
229
215
}
230
216
function write_BrtColor ( color , o ) {
231
- if ( ! o ) o = new_buf ( 8 ) ;
232
- if ( ! color || color . auto ) { o . write_shift ( 4 , 0 ) ; o . write_shift ( 4 , 0 ) ; return o ; }
233
- if ( color . index != null ) {
217
+ if ( ! o ) o = new_buf ( 8 ) ;
218
+ if ( ! color || color . auto ) { o . write_shift ( 4 , 0 ) ; o . write_shift ( 4 , 0 ) ; return o ; }
219
+ if ( color . index != null ) {
234
220
o . write_shift ( 1 , 0x02 ) ;
235
221
o . write_shift ( 1 , color . index ) ;
236
- } else if ( color . theme != null ) {
222
+ } else if ( color . theme != null ) {
237
223
o . write_shift ( 1 , 0x06 ) ;
238
224
o . write_shift ( 1 , color . theme ) ;
239
225
} else {
240
226
o . write_shift ( 1 , 0x05 ) ;
241
227
o . write_shift ( 1 , 0 ) ;
242
228
}
243
229
var nTS = color . tint || 0 ;
244
- if ( nTS > 0 ) nTS *= 32767 ;
245
- else if ( nTS < 0 ) nTS *= 32768 ;
230
+ if ( nTS > 0 ) nTS *= 32767 ;
231
+ else if ( nTS < 0 ) nTS *= 32768 ;
246
232
o . write_shift ( 2 , nTS ) ;
247
- if ( ! color . rgb || color . theme != null ) {
233
+ if ( ! color . rgb || color . theme != null ) {
248
234
o . write_shift ( 2 , 0 ) ;
249
235
o . write_shift ( 1 , 0 ) ;
250
236
o . write_shift ( 1 , 0 ) ;
251
237
} else {
252
238
var rgb = ( color . rgb || 'FFFFFF' ) ;
253
- if ( typeof rgb == 'number' ) rgb = ( "000000" + rgb . toString ( 16 ) ) . slice ( - 6 ) ;
254
- o . write_shift ( 1 , parseInt ( rgb . slice ( 0 , 2 ) , 16 ) ) ;
255
- o . write_shift ( 1 , parseInt ( rgb . slice ( 2 , 4 ) , 16 ) ) ;
256
- o . write_shift ( 1 , parseInt ( rgb . slice ( 4 , 6 ) , 16 ) ) ;
239
+ if ( typeof rgb == 'number' ) rgb = ( "000000" + rgb . toString ( 16 ) ) . slice ( - 6 ) ;
240
+ o . write_shift ( 1 , parseInt ( rgb . slice ( 0 , 2 ) , 16 ) ) ;
241
+ o . write_shift ( 1 , parseInt ( rgb . slice ( 2 , 4 ) , 16 ) ) ;
242
+ o . write_shift ( 1 , parseInt ( rgb . slice ( 4 , 6 ) , 16 ) ) ;
257
243
o . write_shift ( 1 , 0xFF ) ;
258
244
}
259
245
return o ;
@@ -276,14 +262,14 @@ function parse_FontFlags(data/*::, length, opts*/) {
276
262
return out ;
277
263
}
278
264
function write_FontFlags ( font , o ) {
279
- if ( ! o ) o = new_buf ( 2 ) ;
265
+ if ( ! o ) o = new_buf ( 2 ) ;
280
266
var grbit =
281
- ( font . italic ? 0x02 : 0 ) |
282
- ( font . strike ? 0x08 : 0 ) |
283
- ( font . outline ? 0x10 : 0 ) |
284
- ( font . shadow ? 0x20 : 0 ) |
267
+ ( font . italic ? 0x02 : 0 ) |
268
+ ( font . strike ? 0x08 : 0 ) |
269
+ ( font . outline ? 0x10 : 0 ) |
270
+ ( font . shadow ? 0x20 : 0 ) |
285
271
( font . condense ? 0x40 : 0 ) |
286
- ( font . extend ? 0x80 : 0 ) ;
272
+ ( font . extend ? 0x80 : 0 ) ;
287
273
o . write_shift ( 1 , grbit ) ;
288
274
o . write_shift ( 1 , 0 ) ;
289
275
return o ;
@@ -292,13 +278,13 @@ function write_FontFlags(font, o) {
292
278
/* [MS-OLEDS] 2.3.1 and 2.3.2 */
293
279
function parse_ClipboardFormatOrString ( o , w /*:number*/ ) /*:string*/ {
294
280
// $FlowIgnore
295
- var ClipFmt = { 2 : "BITMAP" , 3 : "METAFILEPICT" , 8 : "DIB" , 14 :"ENHMETAFILE" } ;
281
+ var ClipFmt = { 2 : "BITMAP" , 3 : "METAFILEPICT" , 8 : "DIB" , 14 : "ENHMETAFILE" } ;
296
282
var m /*:number*/ = o . read_shift ( 4 ) ;
297
- switch ( m ) {
283
+ switch ( m ) {
298
284
case 0x00000000 : return "" ;
299
- case 0xffffffff : case 0xfffffffe : return ClipFmt [ o . read_shift ( 4 ) ] || "" ;
285
+ case 0xffffffff : case 0xfffffffe : return ClipFmt [ o . read_shift ( 4 ) ] || "" ;
300
286
}
301
- if ( m > 0x190 ) throw new Error ( "Unsupported Clipboard: " + m . toString ( 16 ) ) ;
287
+ if ( m > 0x190 ) throw new Error ( "Unsupported Clipboard: " + m . toString ( 16 ) ) ;
302
288
o . l -= 4 ;
303
289
return o . read_shift ( 0 , w == 1 ? "lpstr" : "lpwstr" ) ;
304
290
}
0 commit comments