@@ -1255,7 +1255,7 @@ return exports;
1255
1255
if ( typeof require !== 'undefined' && typeof module !== 'undefined' && typeof DO_NOT_EXPORT_CFB === 'undefined' ) { module . exports = CFB ; }
1256
1256
function isval ( x ) { return x !== undefined && x !== null ; }
1257
1257
1258
- function keys ( o ) { return Object . keys ( o ) ; }
1258
+ function keys ( o ) { return o != null ? Object . keys ( o ) : [ ] ; }
1259
1259
1260
1260
function evert_key ( obj , key ) {
1261
1261
var o = [ ] , K = keys ( obj ) ;
@@ -2435,6 +2435,8 @@ var CTYPE_XML_ROOT = writextag('Types', null, {
2435
2435
2436
2436
var CTYPE_DEFAULTS = [
2437
2437
[ 'xml' , 'application/xml' ] ,
2438
+ [ 'png' , 'image/png' ] ,
2439
+ [ 'jpg' , 'image/jpeg' ] ,
2438
2440
[ 'bin' , 'application/vnd.ms-excel.sheet.binary.macroEnabled.main' ] ,
2439
2441
[ 'rels' , type2ct . rels [ 0 ] ]
2440
2442
] . map ( function ( x ) {
@@ -2476,6 +2478,7 @@ function write_ct(ct, opts) {
2476
2478
f3 ( 'themes' ) ;
2477
2479
[ 'strs' , 'styles' ] . forEach ( f1 ) ;
2478
2480
[ 'coreprops' , 'extprops' , 'custprops' ] . forEach ( f3 ) ;
2481
+ o [ o . length ] = '<Override PartName="/xl/drawings/drawing1.xml" ContentType="application/vnd.openxmlformats-officedocument.drawing+xml"/>' ;
2479
2482
if ( o . length > 2 ) { o [ o . length ] = ( '</Types>' ) ; o [ 1 ] = o [ 1 ] . replace ( "/>" , ">" ) ; }
2480
2483
return o . join ( "" ) ;
2481
2484
}
@@ -2529,6 +2532,39 @@ var RELS_ROOT = writextag('Relationships', null, {
2529
2532
'xmlns' : XMLNS . RELS
2530
2533
} ) ;
2531
2534
2535
+ var DRAW_ROOT = writextag ( 'xdr:wsDr' , null , {
2536
+ 'xmlns:xdr' : 'http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing' ,
2537
+ 'xmlns:a' : 'http://schemas.openxmlformats.org/drawingml/2006/main'
2538
+ //'xmlns:ns0': XMLNS.RELS,
2539
+ // 'xmlns': XMLNS.RELS
2540
+ } ) ;
2541
+
2542
+ function write_drawing ( images ) {
2543
+ var o = [ ] ;
2544
+ o [ o . length ] = ( XML_HEADER ) ;
2545
+ o [ o . length ] = ( DRAW_ROOT ) ;
2546
+
2547
+ for ( var i = 0 ; i < images . length ; i ++ ) {
2548
+ var image = images [ i ] ;
2549
+ var pos = image . position || { } ;
2550
+ if ( pos . type === 'twoCellAnchor' ) {
2551
+ var from = pos . from || { } , to = pos . to || { } ,
2552
+ fromCol = from . col || 0 , toCol = to . col || 0 ,
2553
+ fromRow = from . row || 0 , toRow = to . row || 0 ;
2554
+
2555
+ var twoCell = '<xdr:from><xdr:col>' + fromCol + '</xdr:col><xdr:colOff>0</xdr:colOff><xdr:row>' + fromRow + '</xdr:row><xdr:rowOff>0</xdr:rowOff></xdr:from>' ;
2556
+ twoCell += '<xdr:to><xdr:col>' + toCol + '</xdr:col><xdr:colOff>0</xdr:colOff><xdr:row>' + toRow + '</xdr:row><xdr:rowOff>99999</xdr:rowOff></xdr:to>' ;
2557
+ twoCell += '<xdr:pic><xdr:nvPicPr><xdr:cNvPr id="' + ( i + 1 ) + '" name="' + image . name + '">'
2558
+ twoCell += '</xdr:cNvPr><xdr:cNvPicPr><a:picLocks noChangeAspect="1"/></xdr:cNvPicPr></xdr:nvPicPr>' ;
2559
+ twoCell += '<xdr:blipFill><a:blip xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:embed="rId' + ( i + 1 ) + '"/>' ;
2560
+ twoCell += '<a:stretch><a:fillRect/></a:stretch></xdr:blipFill><xdr:spPr><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></xdr:spPr></xdr:pic><xdr:clientData/>' ;
2561
+ o [ o . length ] = ( writextag ( 'xdr:twoCellAnchor' , twoCell , images [ i ] . attrs ) ) ;
2562
+ }
2563
+ }
2564
+
2565
+ if ( o . length > 2 ) { o [ o . length ] = ( '</xdr:wsDr>' ) ; o [ 1 ] = o [ 1 ] . replace ( "/>" , ">" ) ; }
2566
+ return o . join ( "" ) ;
2567
+ }
2532
2568
/* TODO */
2533
2569
function write_rels ( rels ) {
2534
2570
var o = [ ] ;
@@ -4601,6 +4637,7 @@ function rgb_tint(hex, tint) {
4601
4637
var DEF_MDW = 7 , MAX_MDW = 15 , MIN_MDW = 1 , MDW = DEF_MDW ;
4602
4638
function width2px ( width ) { return ( ( width + ( ( 128 / MDW ) | 0 ) / 256 ) * MDW ) | 0 ; }
4603
4639
function px2char ( px ) { return ( ( ( px - 5 ) / MDW * 100 + 0.5 ) | 0 ) / 100 ; }
4640
+ function px2pt ( px ) { return px * 72 / 96 ; }
4604
4641
function char2width ( chr ) { return ( ( ( chr * MDW + 5 ) / MDW * 256 ) | 0 ) / 256 ; }
4605
4642
function cycle_width ( collw ) { return char2width ( px2char ( width2px ( collw ) ) ) ; }
4606
4643
function find_mdw ( collw , coll ) {
@@ -7542,8 +7579,20 @@ function write_ws_xml_data(ws, opts, idx, wb) {
7542
7579
if ( ws [ ref ] === undefined ) continue ;
7543
7580
if ( ( cell = write_ws_xml_cell ( ws [ ref ] , ref , ws , opts , idx , wb ) ) != null ) r . push ( cell ) ;
7544
7581
}
7545
- if ( r . length > 0 ) o [ o . length ] = ( writextag ( 'row' , r . join ( "" ) , { r :rr } ) ) ;
7546
- }
7582
+ if ( r . length > 0 ) {
7583
+ // 18.3.1.73 row
7584
+ var params = { r :rr } ;
7585
+ if ( typeof ws [ '!rows' ] !== 'undefined' && ws [ '!rows' ] . length > R ) {
7586
+ var row = ws [ '!rows' ] [ R ] ;
7587
+ if ( row . hidden ) params . hidden = 1 ;
7588
+ var height = - 1 ;
7589
+ if ( row . hpx ) height = px2pt ( row . hpx ) ;
7590
+ else if ( row . hpt ) height = row . hpt ;
7591
+ if ( height > - 1 ) { params . ht = height ; params . customHeight = 1 ; }
7592
+ } ;
7593
+ o [ o . length ] = ( writextag ( 'row' , r . join ( "" ) , params ) ) ;
7594
+ }
7595
+ }
7547
7596
return o . join ( "" ) ;
7548
7597
}
7549
7598
@@ -7570,6 +7619,9 @@ function write_ws_xml(idx, opts, wb) {
7570
7619
7571
7620
if ( ws [ '!merges' ] !== undefined && ws [ '!merges' ] . length > 0 ) o [ o . length ] = ( write_ws_xml_merges ( ws [ '!merges' ] ) ) ;
7572
7621
7622
+ var images = ws [ '!images' ] || [ ] ;
7623
+ if ( images . length ) o [ o . length ] = '<drawing r:id="rId1"/>' ;
7624
+
7573
7625
if ( o . length > 2 ) { o [ o . length ] = ( '</worksheet>' ) ; o [ 1 ] = o [ 1 ] . replace ( "/>" , ">" ) ; }
7574
7626
return o . join ( "" ) ;
7575
7627
}
@@ -11285,6 +11337,9 @@ function add_rels(rels, rId, f, type, relobj) {
11285
11337
rels [ ( '/' + relobj . Target ) . replace ( "//" , "/" ) ] = relobj ;
11286
11338
}
11287
11339
11340
+ RELS . IMG = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" ;
11341
+ RELS . DRAW = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing" ;
11342
+
11288
11343
function write_zip ( wb , opts ) {
11289
11344
if ( wb && ! wb . SSF ) {
11290
11345
wb . SSF = SSF . get_table ( ) ;
@@ -11332,6 +11387,19 @@ function write_zip(wb, opts) {
11332
11387
add_rels ( opts . rels , 1 , f , RELS . WB ) ;
11333
11388
11334
11389
for ( rId = 1 ; rId <= wb . SheetNames . length ; ++ rId ) {
11390
+ var s = wb . SheetNames [ rId - 1 ] , ws = wb . Sheets [ s ] ,
11391
+ images = ws [ '!images' ] || [ ] ;
11392
+ var rels = ws [ '!rels' ] = [ ] , draw_rels = [ ] ;
11393
+ for ( var sId = 1 ; sId < images . length + 1 ; ++ sId ) {
11394
+ var image = images [ sId - 1 ] ;
11395
+ f = 'xl/media/' + image . name ;
11396
+ zip . file ( f , image . data , image . opts ) ;
11397
+ add_rels ( draw_rels , sId , "../media/" + image . name , RELS . IMG ) ;
11398
+ }
11399
+ zip . file ( "xl/drawings/drawing" + rId + "." + wbext , write_drawing ( images ) ) ;
11400
+ add_rels ( rels , rId , "../drawings/drawing" + rId + "." + wbext , RELS . DRAW ) ;
11401
+ zip . file ( "xl/drawings/_rels/drawing" + rId + "." + wbext + ".rels" , write_rels ( draw_rels ) ) ;
11402
+ zip . file ( "xl/worksheets/_rels/sheet" + rId + "." + wbext + '.rels' , write_rels ( rels ) ) ;
11335
11403
f = "xl/worksheets/sheet" + rId + "." + wbext ;
11336
11404
zip . file ( f , write_ws ( rId - 1 , f , opts , wb ) ) ;
11337
11405
ct . sheets . push ( f ) ;
0 commit comments