@@ -95,7 +95,7 @@ public function canRead($pFilename)
95
95
// Open file
96
96
$ this ->_openFile ($ pFilename );
97
97
$ fileHandle = $ this ->_fileHandle ;
98
-
98
+
99
99
// Read sample data (first 2 KB will do)
100
100
$ data = fread ($ fileHandle , 2048 );
101
101
fclose ($ fileHandle );
@@ -407,61 +407,62 @@ public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
407
407
}
408
408
}
409
409
410
- foreach ($ xml ->Styles [0 ] as $ style ) {
411
- $ style_ss = $ style ->attributes ($ namespaces ['ss ' ]);
412
- $ styleID = (string ) $ style_ss ['ID ' ];
413
- // echo 'Style ID = '.$styleID.'<br />';
414
- if ($ styleID == 'Default ' ) {
415
- $ this ->_styles ['Default ' ] = array ();
416
- } else {
417
- $ this ->_styles [$ styleID ] = $ this ->_styles ['Default ' ];
418
- }
419
- foreach ($ style as $ styleType => $ styleData ) {
420
- $ styleAttributes = $ styleData ->attributes ($ namespaces ['ss ' ]);
421
- // echo $styleType.'<br />';
422
- switch ($ styleType ) {
423
- case 'Alignment ' :
424
- foreach ($ styleAttributes as $ styleAttributeKey => $ styleAttributeValue ) {
425
- // echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
426
- $ styleAttributeValue = (string ) $ styleAttributeValue ;
410
+ if (isset ($ xml ->Styles )) {
411
+ foreach ($ xml ->Styles [0 ] as $ style ) {
412
+ $ style_ss = $ style ->attributes ($ namespaces ['ss ' ]);
413
+ $ styleID = (string )$ style_ss ['ID ' ];
414
+ // echo 'Style ID = '.$styleID.'<br />';
415
+ if ($ styleID == 'Default ' ) {
416
+ $ this ->_styles ['Default ' ] = array ();
417
+ } else {
418
+ $ this ->_styles [$ styleID ] = $ this ->_styles ['Default ' ];
419
+ }
420
+ foreach ($ style as $ styleType => $ styleData ) {
421
+ $ styleAttributes = $ styleData ->attributes ($ namespaces ['ss ' ]);
422
+ // echo $styleType.'<br />';
423
+ switch ($ styleType ) {
424
+ case 'Alignment ' :
425
+ foreach ($ styleAttributes as $ styleAttributeKey => $ styleAttributeValue ) {
426
+ // echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
427
+ $ styleAttributeValue = (string )$ styleAttributeValue ;
427
428
switch ($ styleAttributeKey ) {
428
429
case 'Vertical ' :
429
- if (self ::identifyFixedStyleValue ($ verticalAlignmentStyles ,$ styleAttributeValue )) {
430
- $ this ->_styles [$ styleID ]['alignment ' ]['vertical ' ] = $ styleAttributeValue ;
431
- }
432
- break ;
430
+ if (self ::identifyFixedStyleValue ($ verticalAlignmentStyles , $ styleAttributeValue )) {
431
+ $ this ->_styles [$ styleID ]['alignment ' ]['vertical ' ] = $ styleAttributeValue ;
432
+ }
433
+ break ;
433
434
case 'Horizontal ' :
434
- if (self ::identifyFixedStyleValue ($ horizontalAlignmentStyles ,$ styleAttributeValue )) {
435
- $ this ->_styles [$ styleID ]['alignment ' ]['horizontal ' ] = $ styleAttributeValue ;
436
- }
437
- break ;
435
+ if (self ::identifyFixedStyleValue ($ horizontalAlignmentStyles , $ styleAttributeValue )) {
436
+ $ this ->_styles [$ styleID ]['alignment ' ]['horizontal ' ] = $ styleAttributeValue ;
437
+ }
438
+ break ;
438
439
case 'WrapText ' :
439
- $ this ->_styles [$ styleID ]['alignment ' ]['wrap ' ] = true ;
440
- break ;
440
+ $ this ->_styles [$ styleID ]['alignment ' ]['wrap ' ] = true ;
441
+ break ;
441
442
}
442
443
}
443
444
break ;
444
- case 'Borders ' :
445
- foreach ($ styleData ->Border as $ borderStyle ) {
445
+ case 'Borders ' :
446
+ foreach ($ styleData ->Border as $ borderStyle ) {
446
447
$ borderAttributes = $ borderStyle ->attributes ($ namespaces ['ss ' ]);
447
448
$ thisBorder = array ();
448
- foreach ($ borderAttributes as $ borderStyleKey => $ borderStyleValue ) {
449
- // echo $borderStyleKey.' = '.$borderStyleValue.'<br />';
449
+ foreach ($ borderAttributes as $ borderStyleKey => $ borderStyleValue ) {
450
+ // echo $borderStyleKey.' = '.$borderStyleValue.'<br />';
450
451
switch ($ borderStyleKey ) {
451
452
case 'LineStyle ' :
452
- $ thisBorder ['style ' ] = PHPExcel_Style_Border::BORDER_MEDIUM ;
453
- // $thisBorder['style'] = $borderStyleValue;
454
- break ;
453
+ $ thisBorder ['style ' ] = PHPExcel_Style_Border::BORDER_MEDIUM ;
454
+ // $thisBorder['style'] = $borderStyleValue;
455
+ break ;
455
456
case 'Weight ' :
456
- // $thisBorder['style'] = $borderStyleValue;
457
- break ;
457
+ // $thisBorder['style'] = $borderStyleValue;
458
+ break ;
458
459
case 'Position ' :
459
- $ borderPosition = strtolower ($ borderStyleValue );
460
- break ;
460
+ $ borderPosition = strtolower ($ borderStyleValue );
461
+ break ;
461
462
case 'Color ' :
462
- $ borderColour = substr ($ borderStyleValue ,1 );
463
- $ thisBorder ['color ' ]['rgb ' ] = $ borderColour ;
464
- break ;
463
+ $ borderColour = substr ($ borderStyleValue , 1 );
464
+ $ thisBorder ['color ' ]['rgb ' ] = $ borderColour ;
465
+ break ;
465
466
}
466
467
}
467
468
if (!empty ($ thisBorder )) {
@@ -471,67 +472,68 @@ public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
471
472
}
472
473
}
473
474
break ;
474
- case 'Font ' :
475
- foreach ($ styleAttributes as $ styleAttributeKey => $ styleAttributeValue ) {
476
- // echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
477
- $ styleAttributeValue = (string ) $ styleAttributeValue ;
475
+ case 'Font ' :
476
+ foreach ($ styleAttributes as $ styleAttributeKey => $ styleAttributeValue ) {
477
+ // echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
478
+ $ styleAttributeValue = (string )$ styleAttributeValue ;
478
479
switch ($ styleAttributeKey ) {
479
480
case 'FontName ' :
480
- $ this ->_styles [$ styleID ]['font ' ]['name ' ] = $ styleAttributeValue ;
481
- break ;
481
+ $ this ->_styles [$ styleID ]['font ' ]['name ' ] = $ styleAttributeValue ;
482
+ break ;
482
483
case 'Size ' :
483
- $ this ->_styles [$ styleID ]['font ' ]['size ' ] = $ styleAttributeValue ;
484
- break ;
484
+ $ this ->_styles [$ styleID ]['font ' ]['size ' ] = $ styleAttributeValue ;
485
+ break ;
485
486
case 'Color ' :
486
- $ this ->_styles [$ styleID ]['font ' ]['color ' ]['rgb ' ] = substr ($ styleAttributeValue ,1 );
487
- break ;
487
+ $ this ->_styles [$ styleID ]['font ' ]['color ' ]['rgb ' ] = substr ($ styleAttributeValue , 1 );
488
+ break ;
488
489
case 'Bold ' :
489
- $ this ->_styles [$ styleID ]['font ' ]['bold ' ] = true ;
490
- break ;
490
+ $ this ->_styles [$ styleID ]['font ' ]['bold ' ] = true ;
491
+ break ;
491
492
case 'Italic ' :
492
- $ this ->_styles [$ styleID ]['font ' ]['italic ' ] = true ;
493
- break ;
493
+ $ this ->_styles [$ styleID ]['font ' ]['italic ' ] = true ;
494
+ break ;
494
495
case 'Underline ' :
495
- if (self ::identifyFixedStyleValue ($ underlineStyles ,$ styleAttributeValue )) {
496
- $ this ->_styles [$ styleID ]['font ' ]['underline ' ] = $ styleAttributeValue ;
497
- }
498
- break ;
496
+ if (self ::identifyFixedStyleValue ($ underlineStyles , $ styleAttributeValue )) {
497
+ $ this ->_styles [$ styleID ]['font ' ]['underline ' ] = $ styleAttributeValue ;
498
+ }
499
+ break ;
499
500
}
500
501
}
501
502
break ;
502
- case 'Interior ' :
503
- foreach ($ styleAttributes as $ styleAttributeKey => $ styleAttributeValue ) {
504
- // echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
503
+ case 'Interior ' :
504
+ foreach ($ styleAttributes as $ styleAttributeKey => $ styleAttributeValue ) {
505
+ // echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
505
506
switch ($ styleAttributeKey ) {
506
507
case 'Color ' :
507
- $ this ->_styles [$ styleID ]['fill ' ]['color ' ]['rgb ' ] = substr ($ styleAttributeValue ,1 );
508
- break ;
508
+ $ this ->_styles [$ styleID ]['fill ' ]['color ' ]['rgb ' ] = substr ($ styleAttributeValue , 1 );
509
+ break ;
509
510
}
510
511
}
511
512
break ;
512
- case 'NumberFormat ' :
513
- foreach ($ styleAttributes as $ styleAttributeKey => $ styleAttributeValue ) {
514
- // echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
515
- $ styleAttributeValue = str_replace ($ fromFormats ,$ toFormats ,$ styleAttributeValue );
513
+ case 'NumberFormat ' :
514
+ foreach ($ styleAttributes as $ styleAttributeKey => $ styleAttributeValue ) {
515
+ // echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
516
+ $ styleAttributeValue = str_replace ($ fromFormats , $ toFormats , $ styleAttributeValue );
516
517
switch ($ styleAttributeValue ) {
517
518
case 'Short Date ' :
518
- $ styleAttributeValue = 'dd/mm/yyyy ' ;
519
- break ;
519
+ $ styleAttributeValue = 'dd/mm/yyyy ' ;
520
+ break ;
520
521
}
521
522
if ($ styleAttributeValue > '' ) {
522
523
$ this ->_styles [$ styleID ]['numberformat ' ]['code ' ] = $ styleAttributeValue ;
523
524
}
524
525
}
525
526
break ;
526
- case 'Protection ' :
527
- foreach ($ styleAttributes as $ styleAttributeKey => $ styleAttributeValue ) {
528
- // echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
527
+ case 'Protection ' :
528
+ foreach ($ styleAttributes as $ styleAttributeKey => $ styleAttributeValue ) {
529
+ // echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
529
530
}
530
531
break ;
532
+ }
531
533
}
534
+ // print_r($this->_styles[$styleID]);
535
+ // echo '<hr />';
532
536
}
533
- // print_r($this->_styles[$styleID]);
534
- // echo '<hr />';
535
537
}
536
538
// echo '<hr />';
537
539
0 commit comments