Conditions | 155 |
Paths | > 20000 |
Total Lines | 566 |
Code Lines | 424 |
Lines | 22 |
Ratio | 3.89 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
206 | if (!file_exists($pFilename)) { |
||
207 | throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); |
||
208 | } |
||
209 | |||
210 | $timezoneObj = new DateTimeZone('Europe/London'); |
||
211 | $GMT = new DateTimeZone('UTC'); |
||
212 | |||
213 | $gFileData = $this->gzfileGetContents($pFilename); |
||
214 | |||
215 | // echo '<pre>'; |
||
216 | // echo htmlentities($gFileData,ENT_QUOTES,'UTF-8'); |
||
217 | // echo '</pre><hr />'; |
||
218 | // |
||
219 | $xml = simplexml_load_string($this->securityScan($gFileData), 'SimpleXMLElement', \PhpSpreadsheet\Settings::getLibXmlLoaderOptions()); |
||
220 | $namespacesMeta = $xml->getNamespaces(true); |
||
221 | |||
222 | // var_dump($namespacesMeta); |
||
223 | // |
||
224 | $gnmXML = $xml->children($namespacesMeta['gnm']); |
||
225 | |||
226 | $docProps = $spreadsheet->getProperties(); |
||
227 | // Document Properties are held differently, depending on the version of Gnumeric |
||
228 | if (isset($namespacesMeta['office'])) { |
||
229 | $officeXML = $xml->children($namespacesMeta['office']); |
||
230 | $officeDocXML = $officeXML->{'document-meta'}; |
||
231 | $officeDocMetaXML = $officeDocXML->meta; |
||
232 | |||
233 | foreach ($officeDocMetaXML as $officePropertyData) { |
||
234 | $officePropertyDC = array(); |
||
235 | if (isset($namespacesMeta['dc'])) { |
||
236 | $officePropertyDC = $officePropertyData->children($namespacesMeta['dc']); |
||
237 | } |
||
238 | foreach ($officePropertyDC as $propertyName => $propertyValue) { |
||
239 | $propertyValue = (string) $propertyValue; |
||
240 | switch ($propertyName) { |
||
241 | case 'title': |
||
242 | $docProps->setTitle(trim($propertyValue)); |
||
243 | break; |
||
244 | case 'subject': |
||
245 | $docProps->setSubject(trim($propertyValue)); |
||
246 | break; |
||
247 | case 'creator': |
||
248 | $docProps->setCreator(trim($propertyValue)); |
||
249 | $docProps->setLastModifiedBy(trim($propertyValue)); |
||
250 | break; |
||
251 | View Code Duplication | case 'date': |
|
252 | $creationDate = strtotime(trim($propertyValue)); |
||
253 | $docProps->setCreated($creationDate); |
||
254 | $docProps->setModified($creationDate); |
||
255 | break; |
||
256 | case 'description': |
||
257 | $docProps->setDescription(trim($propertyValue)); |
||
258 | break; |
||
259 | } |
||
260 | } |
||
261 | $officePropertyMeta = array(); |
||
262 | if (isset($namespacesMeta['meta'])) { |
||
263 | $officePropertyMeta = $officePropertyData->children($namespacesMeta['meta']); |
||
264 | } |
||
265 | foreach ($officePropertyMeta as $propertyName => $propertyValue) { |
||
266 | $attributes = $propertyValue->attributes($namespacesMeta['meta']); |
||
267 | $propertyValue = (string) $propertyValue; |
||
268 | switch ($propertyName) { |
||
269 | case 'keyword': |
||
270 | $docProps->setKeywords(trim($propertyValue)); |
||
271 | break; |
||
272 | case 'initial-creator': |
||
273 | $docProps->setCreator(trim($propertyValue)); |
||
274 | $docProps->setLastModifiedBy(trim($propertyValue)); |
||
275 | break; |
||
276 | View Code Duplication | case 'creation-date': |
|
277 | $creationDate = strtotime(trim($propertyValue)); |
||
278 | $docProps->setCreated($creationDate); |
||
279 | $docProps->setModified($creationDate); |
||
280 | break; |
||
281 | case 'user-defined': |
||
282 | list(, $attrName) = explode(':', $attributes['name']); |
||
283 | switch ($attrName) { |
||
284 | case 'publisher': |
||
285 | $docProps->setCompany(trim($propertyValue)); |
||
286 | break; |
||
287 | case 'category': |
||
288 | $docProps->setCategory(trim($propertyValue)); |
||
289 | break; |
||
290 | case 'manager': |
||
291 | $docProps->setManager(trim($propertyValue)); |
||
292 | break; |
||
293 | } |
||
294 | break; |
||
295 | } |
||
296 | } |
||
297 | } |
||
298 | } elseif (isset($gnmXML->Summary)) { |
||
299 | foreach ($gnmXML->Summary->Item as $summaryItem) { |
||
300 | $propertyName = $summaryItem->name; |
||
301 | $propertyValue = $summaryItem->{'val-string'}; |
||
302 | switch ($propertyName) { |
||
303 | case 'title': |
||
304 | $docProps->setTitle(trim($propertyValue)); |
||
305 | break; |
||
306 | case 'comments': |
||
307 | $docProps->setDescription(trim($propertyValue)); |
||
308 | break; |
||
309 | case 'keywords': |
||
310 | $docProps->setKeywords(trim($propertyValue)); |
||
311 | break; |
||
312 | case 'category': |
||
313 | $docProps->setCategory(trim($propertyValue)); |
||
314 | break; |
||
315 | case 'manager': |
||
316 | $docProps->setManager(trim($propertyValue)); |
||
317 | break; |
||
318 | case 'author': |
||
319 | $docProps->setCreator(trim($propertyValue)); |
||
320 | $docProps->setLastModifiedBy(trim($propertyValue)); |
||
321 | break; |
||
322 | case 'company': |
||
323 | $docProps->setCompany(trim($propertyValue)); |
||
324 | break; |
||
325 | } |
||
326 | } |
||
327 | } |
||
328 | |||
329 | $worksheetID = 0; |
||
330 | foreach ($gnmXML->Sheets->Sheet as $sheet) { |
||
331 | $worksheetName = (string) $sheet->Name; |
||
332 | // echo '<b>Worksheet: ', $worksheetName,'</b><br />'; |
||
333 | if ((isset($this->loadSheetsOnly)) && (!in_array($worksheetName, $this->loadSheetsOnly))) { |
||
334 | continue; |
||
335 | } |
||
336 | |||
337 | $maxRow = $maxCol = 0; |
||
338 | |||
339 | // Create new Worksheet |
||
340 | $spreadsheet->createSheet(); |
||
341 | $spreadsheet->setActiveSheetIndex($worksheetID); |
||
342 | // Use false for $updateFormulaCellReferences to prevent adjustment of worksheet references in formula |
||
343 | // cells... during the load, all formulae should be correct, and we're simply bringing the worksheet |
||
344 | // name in line with the formula, not the reverse |
||
345 | $spreadsheet->getActiveSheet()->setTitle($worksheetName, false); |
||
346 | |||
347 | if ((!$this->readDataOnly) && (isset($sheet->PrintInformation))) { |
||
348 | if (isset($sheet->PrintInformation->Margins)) { |
||
349 | foreach ($sheet->PrintInformation->Margins->children('gnm', true) as $key => $margin) { |
||
350 | $marginAttributes = $margin->attributes(); |
||
351 | $marginSize = 72 / 100; // Default |
||
352 | switch ($marginAttributes['PrefUnit']) { |
||
353 | case 'mm': |
||
354 | $marginSize = intval($marginAttributes['Points']) / 100; |
||
355 | break; |
||
356 | } |
||
357 | switch ($key) { |
||
358 | case 'top': |
||
359 | $spreadsheet->getActiveSheet()->getPageMargins()->setTop($marginSize); |
||
360 | break; |
||
361 | case 'bottom': |
||
362 | $spreadsheet->getActiveSheet()->getPageMargins()->setBottom($marginSize); |
||
363 | break; |
||
364 | case 'left': |
||
365 | $spreadsheet->getActiveSheet()->getPageMargins()->setLeft($marginSize); |
||
366 | break; |
||
367 | case 'right': |
||
368 | $spreadsheet->getActiveSheet()->getPageMargins()->setRight($marginSize); |
||
369 | break; |
||
370 | case 'header': |
||
371 | $spreadsheet->getActiveSheet()->getPageMargins()->setHeader($marginSize); |
||
372 | break; |
||
373 | case 'footer': |
||
374 | $spreadsheet->getActiveSheet()->getPageMargins()->setFooter($marginSize); |
||
375 | break; |
||
376 | } |
||
377 | } |
||
378 | } |
||
379 | } |
||
380 | |||
381 | foreach ($sheet->Cells->Cell as $cell) { |
||
382 | $cellAttributes = $cell->attributes(); |
||
383 | $row = (int) $cellAttributes->Row + 1; |
||
384 | $column = (int) $cellAttributes->Col; |
||
385 | |||
386 | if ($row > $maxRow) { |
||
387 | $maxRow = $row; |
||
388 | } |
||
389 | if ($column > $maxCol) { |
||
390 | $maxCol = $column; |
||
391 | } |
||
392 | |||
393 | $column = \PhpSpreadsheet\Cell::stringFromColumnIndex($column); |
||
394 | |||
395 | // Read cell? |
||
396 | if ($this->getReadFilter() !== null) { |
||
397 | if (!$this->getReadFilter()->readCell($column, $row, $worksheetName)) { |
||
398 | continue; |
||
399 | } |
||
400 | } |
||
401 | |||
402 | $ValueType = $cellAttributes->ValueType; |
||
403 | $ExprID = (string) $cellAttributes->ExprID; |
||
404 | // echo 'Cell ', $column, $row,'<br />'; |
||
405 | // echo 'Type is ', $ValueType,'<br />'; |
||
406 | // echo 'Value is ', $cell,'<br />'; |
||
407 | $type = \PhpSpreadsheet\Cell\DataType::TYPE_FORMULA; |
||
408 | if ($ExprID > '') { |
||
409 | if (((string) $cell) > '') { |
||
410 | $this->expressions[$ExprID] = array( |
||
411 | 'column' => $cellAttributes->Col, |
||
412 | 'row' => $cellAttributes->Row, |
||
413 | 'formula' => (string) $cell |
||
414 | ); |
||
415 | // echo 'NEW EXPRESSION ', $ExprID,'<br />'; |
||
416 | } else { |
||
417 | $expression = $this->expressions[$ExprID]; |
||
418 | |||
419 | $cell = $this->referenceHelper->updateFormulaReferences( |
||
420 | $expression['formula'], |
||
421 | 'A1', |
||
422 | $cellAttributes->Col - $expression['column'], |
||
423 | $cellAttributes->Row - $expression['row'], |
||
424 | $worksheetName |
||
425 | ); |
||
426 | // echo 'SHARED EXPRESSION ', $ExprID,'<br />'; |
||
427 | // echo 'New Value is ', $cell,'<br />'; |
||
428 | } |
||
429 | $type = \PhpSpreadsheet\Cell\DataType::TYPE_FORMULA; |
||
430 | } else { |
||
431 | switch ($ValueType) { |
||
432 | case '10': // NULL |
||
433 | $type = \PhpSpreadsheet\Cell\DataType::TYPE_NULL; |
||
434 | break; |
||
435 | case '20': // Boolean |
||
436 | $type = \PhpSpreadsheet\Cell\DataType::TYPE_BOOL; |
||
437 | $cell = ($cell == 'TRUE') ? true: false; |
||
438 | break; |
||
439 | case '30': // Integer |
||
440 | $cell = intval($cell); |
||
441 | // Excel 2007+ doesn't differentiate between integer and float, so set the value and dropthru to the next (numeric) case |
||
442 | case '40': // Float |
||
443 | $type = \PhpSpreadsheet\Cell\DataType::TYPE_NUMERIC; |
||
444 | break; |
||
445 | case '50': // Error |
||
446 | $type = \PhpSpreadsheet\Cell\DataType::TYPE_ERROR; |
||
447 | break; |
||
448 | case '60': // String |
||
449 | $type = \PhpSpreadsheet\Cell\DataType::TYPE_STRING; |
||
450 | break; |
||
451 | case '70': // Cell Range |
||
452 | case '80': // Array |
||
453 | } |
||
454 | } |
||
455 | $spreadsheet->getActiveSheet()->getCell($column.$row)->setValueExplicit($cell, $type); |
||
456 | } |
||
457 | |||
458 | if ((!$this->readDataOnly) && (isset($sheet->Objects))) { |
||
459 | foreach ($sheet->Objects->children('gnm', true) as $key => $comment) { |
||
460 | $commentAttributes = $comment->attributes(); |
||
461 | // Only comment objects are handled at the moment |
||
462 | if ($commentAttributes->Text) { |
||
463 | $spreadsheet->getActiveSheet()->getComment((string)$commentAttributes->ObjectBound)->setAuthor((string)$commentAttributes->Author)->setText($this->parseRichText((string)$commentAttributes->Text)); |
||
464 | } |
||
465 | } |
||
466 | } |
||
467 | // echo '$maxCol=', $maxCol,'; $maxRow=', $maxRow,'<br />'; |
||
468 | // |
||
469 | foreach ($sheet->Styles->StyleRegion as $styleRegion) { |
||
470 | $styleAttributes = $styleRegion->attributes(); |
||
471 | if (($styleAttributes['startRow'] <= $maxRow) && |
||
472 | ($styleAttributes['startCol'] <= $maxCol)) { |
||
473 | $startColumn = \PhpSpreadsheet\Cell::stringFromColumnIndex((int) $styleAttributes['startCol']); |
||
474 | $startRow = $styleAttributes['startRow'] + 1; |
||
475 | |||
476 | $endColumn = ($styleAttributes['endCol'] > $maxCol) ? $maxCol : (int) $styleAttributes['endCol']; |
||
477 | $endColumn = \PhpSpreadsheet\Cell::stringFromColumnIndex($endColumn); |
||
478 | $endRow = ($styleAttributes['endRow'] > $maxRow) ? $maxRow : $styleAttributes['endRow']; |
||
479 | $endRow += 1; |
||
480 | $cellRange = $startColumn.$startRow.':'.$endColumn.$endRow; |
||
481 | // echo $cellRange,'<br />'; |
||
482 | |||
483 | $styleAttributes = $styleRegion->Style->attributes(); |
||
484 | // var_dump($styleAttributes); |
||
485 | // echo '<br />'; |
||
486 | |||
487 | // We still set the number format mask for date/time values, even if readDataOnly is true |
||
488 | if ((!$this->readDataOnly) || |
||
489 | (\PhpSpreadsheet\Shared\Date::isDateTimeFormatCode((string) $styleAttributes['Format']))) { |
||
490 | $styleArray = array(); |
||
491 | $styleArray['numberformat']['code'] = (string) $styleAttributes['Format']; |
||
492 | // If readDataOnly is false, we set all formatting information |
||
493 | if (!$this->readDataOnly) { |
||
494 | switch ($styleAttributes['HAlign']) { |
||
495 | case '1': |
||
496 | $styleArray['alignment']['horizontal'] = \PhpSpreadsheet\Style\Alignment::HORIZONTAL_GENERAL; |
||
497 | break; |
||
498 | case '2': |
||
499 | $styleArray['alignment']['horizontal'] = \PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT; |
||
500 | break; |
||
501 | case '4': |
||
502 | $styleArray['alignment']['horizontal'] = \PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT; |
||
503 | break; |
||
504 | case '8': |
||
505 | $styleArray['alignment']['horizontal'] = \PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER; |
||
506 | break; |
||
507 | case '16': |
||
508 | case '64': |
||
509 | $styleArray['alignment']['horizontal'] = \PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER_CONTINUOUS; |
||
510 | break; |
||
511 | case '32': |
||
512 | $styleArray['alignment']['horizontal'] = \PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY; |
||
513 | break; |
||
514 | } |
||
515 | |||
516 | switch ($styleAttributes['VAlign']) { |
||
517 | case '1': |
||
518 | $styleArray['alignment']['vertical'] = \PhpSpreadsheet\Style\Alignment::VERTICAL_TOP; |
||
519 | break; |
||
520 | case '2': |
||
521 | $styleArray['alignment']['vertical'] = \PhpSpreadsheet\Style\Alignment::VERTICAL_BOTTOM; |
||
522 | break; |
||
523 | case '4': |
||
524 | $styleArray['alignment']['vertical'] = \PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER; |
||
525 | break; |
||
526 | case '8': |
||
527 | $styleArray['alignment']['vertical'] = \PhpSpreadsheet\Style\Alignment::VERTICAL_JUSTIFY; |
||
528 | break; |
||
529 | } |
||
530 | |||
531 | $styleArray['alignment']['wrap'] = ($styleAttributes['WrapText'] == '1') ? true : false; |
||
532 | $styleArray['alignment']['shrinkToFit'] = ($styleAttributes['ShrinkToFit'] == '1') ? true : false; |
||
533 | $styleArray['alignment']['indent'] = (intval($styleAttributes["Indent"]) > 0) ? $styleAttributes["indent"] : 0; |
||
534 | |||
535 | $RGB = self::parseGnumericColour($styleAttributes["Fore"]); |
||
536 | $styleArray['font']['color']['rgb'] = $RGB; |
||
537 | $RGB = self::parseGnumericColour($styleAttributes["Back"]); |
||
538 | $shade = $styleAttributes["Shade"]; |
||
539 | if (($RGB != '000000') || ($shade != '0')) { |
||
540 | $styleArray['fill']['color']['rgb'] = $styleArray['fill']['startcolor']['rgb'] = $RGB; |
||
541 | $RGB2 = self::parseGnumericColour($styleAttributes["PatternColor"]); |
||
542 | $styleArray['fill']['endcolor']['rgb'] = $RGB2; |
||
543 | switch ($shade) { |
||
544 | case '1': |
||
545 | $styleArray['fill']['type'] = \PhpSpreadsheet\Style\Fill::FILL_SOLID; |
||
546 | break; |
||
547 | case '2': |
||
548 | $styleArray['fill']['type'] = \PhpSpreadsheet\Style\Fill::FILL_GRADIENT_LINEAR; |
||
549 | break; |
||
550 | case '3': |
||
551 | $styleArray['fill']['type'] = \PhpSpreadsheet\Style\Fill::FILL_GRADIENT_PATH; |
||
552 | break; |
||
553 | case '4': |
||
554 | $styleArray['fill']['type'] = \PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKDOWN; |
||
555 | break; |
||
556 | case '5': |
||
557 | $styleArray['fill']['type'] = \PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKGRAY; |
||
558 | break; |
||
559 | case '6': |
||
560 | $styleArray['fill']['type'] = \PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKGRID; |
||
561 | break; |
||
562 | case '7': |
||
563 | $styleArray['fill']['type'] = \PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKHORIZONTAL; |
||
564 | break; |
||
565 | case '8': |
||
566 | $styleArray['fill']['type'] = \PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKTRELLIS; |
||
567 | break; |
||
568 | case '9': |
||
569 | $styleArray['fill']['type'] = \PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKUP; |
||
570 | break; |
||
571 | case '10': |
||
572 | $styleArray['fill']['type'] = \PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKVERTICAL; |
||
573 | break; |
||
574 | case '11': |
||
575 | $styleArray['fill']['type'] = \PhpSpreadsheet\Style\Fill::FILL_PATTERN_GRAY0625; |
||
576 | break; |
||
577 | case '12': |
||
578 | $styleArray['fill']['type'] = \PhpSpreadsheet\Style\Fill::FILL_PATTERN_GRAY125; |
||
579 | break; |
||
580 | case '13': |
||
581 | $styleArray['fill']['type'] = \PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTDOWN; |
||
582 | break; |
||
583 | case '14': |
||
584 | $styleArray['fill']['type'] = \PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTGRAY; |
||
585 | break; |
||
586 | case '15': |
||
587 | $styleArray['fill']['type'] = \PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTGRID; |
||
588 | break; |
||
589 | case '16': |
||
590 | $styleArray['fill']['type'] = \PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTHORIZONTAL; |
||
591 | break; |
||
592 | case '17': |
||
593 | $styleArray['fill']['type'] = \PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTTRELLIS; |
||
594 | break; |
||
595 | case '18': |
||
596 | $styleArray['fill']['type'] = \PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTUP; |
||
597 | break; |
||
598 | case '19': |
||
599 | $styleArray['fill']['type'] = \PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTVERTICAL; |
||
600 | break; |
||
601 | case '20': |
||
602 | $styleArray['fill']['type'] = \PhpSpreadsheet\Style\Fill::FILL_PATTERN_MEDIUMGRAY; |
||
603 | break; |
||
604 | } |
||
605 | } |
||
606 | |||
607 | $fontAttributes = $styleRegion->Style->Font->attributes(); |
||
608 | // var_dump($fontAttributes); |
||
609 | // echo '<br />'; |
||
610 | $styleArray['font']['name'] = (string) $styleRegion->Style->Font; |
||
611 | $styleArray['font']['size'] = intval($fontAttributes['Unit']); |
||
612 | $styleArray['font']['bold'] = ($fontAttributes['Bold'] == '1') ? true : false; |
||
613 | $styleArray['font']['italic'] = ($fontAttributes['Italic'] == '1') ? true : false; |
||
614 | $styleArray['font']['strike'] = ($fontAttributes['StrikeThrough'] == '1') ? true : false; |
||
615 | switch ($fontAttributes['Underline']) { |
||
616 | case '1': |
||
617 | $styleArray['font']['underline'] = \PhpSpreadsheet\Style\Font::UNDERLINE_SINGLE; |
||
618 | break; |
||
619 | case '2': |
||
620 | $styleArray['font']['underline'] = \PhpSpreadsheet\Style\Font::UNDERLINE_DOUBLE; |
||
621 | break; |
||
622 | case '3': |
||
623 | $styleArray['font']['underline'] = \PhpSpreadsheet\Style\Font::UNDERLINE_SINGLEACCOUNTING; |
||
624 | break; |
||
625 | case '4': |
||
626 | $styleArray['font']['underline'] = \PhpSpreadsheet\Style\Font::UNDERLINE_DOUBLEACCOUNTING; |
||
627 | break; |
||
628 | default: |
||
629 | $styleArray['font']['underline'] = \PhpSpreadsheet\Style\Font::UNDERLINE_NONE; |
||
630 | break; |
||
631 | } |
||
632 | switch ($fontAttributes['Script']) { |
||
633 | case '1': |
||
634 | $styleArray['font']['superScript'] = true; |
||
635 | break; |
||
636 | case '-1': |
||
637 | $styleArray['font']['subScript'] = true; |
||
638 | break; |
||
639 | } |
||
640 | |||
641 | if (isset($styleRegion->Style->StyleBorder)) { |
||
642 | View Code Duplication | if (isset($styleRegion->Style->StyleBorder->Top)) { |
|
643 | $styleArray['borders']['top'] = self::parseBorderAttributes($styleRegion->Style->StyleBorder->Top->attributes()); |
||
644 | } |
||
645 | View Code Duplication | if (isset($styleRegion->Style->StyleBorder->Bottom)) { |
|
646 | $styleArray['borders']['bottom'] = self::parseBorderAttributes($styleRegion->Style->StyleBorder->Bottom->attributes()); |
||
647 | } |
||
648 | View Code Duplication | if (isset($styleRegion->Style->StyleBorder->Left)) { |
|
649 | $styleArray['borders']['left'] = self::parseBorderAttributes($styleRegion->Style->StyleBorder->Left->attributes()); |
||
650 | } |
||
651 | View Code Duplication | if (isset($styleRegion->Style->StyleBorder->Right)) { |
|
652 | $styleArray['borders']['right'] = self::parseBorderAttributes($styleRegion->Style->StyleBorder->Right->attributes()); |
||
653 | } |
||
654 | if ((isset($styleRegion->Style->StyleBorder->Diagonal)) && (isset($styleRegion->Style->StyleBorder->{'Rev-Diagonal'}))) { |
||
655 | $styleArray['borders']['diagonal'] = self::parseBorderAttributes($styleRegion->Style->StyleBorder->Diagonal->attributes()); |
||
656 | $styleArray['borders']['diagonaldirection'] = \PhpSpreadsheet\Style\Borders::DIAGONAL_BOTH; |
||
657 | } elseif (isset($styleRegion->Style->StyleBorder->Diagonal)) { |
||
658 | $styleArray['borders']['diagonal'] = self::parseBorderAttributes($styleRegion->Style->StyleBorder->Diagonal->attributes()); |
||
659 | $styleArray['borders']['diagonaldirection'] = \PhpSpreadsheet\Style\Borders::DIAGONAL_UP; |
||
660 | } elseif (isset($styleRegion->Style->StyleBorder->{'Rev-Diagonal'})) { |
||
661 | $styleArray['borders']['diagonal'] = self::parseBorderAttributes($styleRegion->Style->StyleBorder->{'Rev-Diagonal'}->attributes()); |
||
662 | $styleArray['borders']['diagonaldirection'] = \PhpSpreadsheet\Style\Borders::DIAGONAL_DOWN; |
||
663 | } |
||
664 | } |
||
665 | if (isset($styleRegion->Style->HyperLink)) { |
||
666 | // TO DO |
||
667 | $hyperlink = $styleRegion->Style->HyperLink->attributes(); |
||
668 | } |
||
669 | } |
||
670 | // var_dump($styleArray); |
||
671 | // echo '<br />'; |
||
672 | $spreadsheet->getActiveSheet()->getStyle($cellRange)->applyFromArray($styleArray); |
||
673 | } |
||
674 | } |
||
675 | } |
||
676 | |||
677 | if ((!$this->readDataOnly) && (isset($sheet->Cols))) { |
||
678 | // Column Widths |
||
679 | $columnAttributes = $sheet->Cols->attributes(); |
||
680 | $defaultWidth = $columnAttributes['DefaultSizePts'] / 5.4; |
||
681 | $c = 0; |
||
682 | foreach ($sheet->Cols->ColInfo as $columnOverride) { |
||
683 | $columnAttributes = $columnOverride->attributes(); |
||
684 | $column = $columnAttributes['No']; |
||
685 | $columnWidth = $columnAttributes['Unit'] / 5.4; |
||
686 | $hidden = ((isset($columnAttributes['Hidden'])) && ($columnAttributes['Hidden'] == '1')) ? true : false; |
||
687 | $columnCount = (isset($columnAttributes['Count'])) ? $columnAttributes['Count'] : 1; |
||
688 | while ($c < $column) { |
||
689 | $spreadsheet->getActiveSheet()->getColumnDimension(\PhpSpreadsheet\Cell::stringFromColumnIndex($c))->setWidth($defaultWidth); |
||
690 | ++$c; |
||
691 | } |
||
692 | while (($c < ($column+$columnCount)) && ($c <= $maxCol)) { |
||
693 | $spreadsheet->getActiveSheet()->getColumnDimension(\PhpSpreadsheet\Cell::stringFromColumnIndex($c))->setWidth($columnWidth); |
||
694 | if ($hidden) { |
||
695 | $spreadsheet->getActiveSheet()->getColumnDimension(\PhpSpreadsheet\Cell::stringFromColumnIndex($c))->setVisible(false); |
||
696 | } |
||
697 | ++$c; |
||
698 | } |
||
699 | } |
||
700 | while ($c <= $maxCol) { |
||
701 | $spreadsheet->getActiveSheet()->getColumnDimension(\PhpSpreadsheet\Cell::stringFromColumnIndex($c))->setWidth($defaultWidth); |
||
702 | ++$c; |
||
703 | } |
||
704 | } |
||
705 | |||
706 | if ((!$this->readDataOnly) && (isset($sheet->Rows))) { |
||
707 | // Row Heights |
||
708 | $rowAttributes = $sheet->Rows->attributes(); |
||
709 | $defaultHeight = $rowAttributes['DefaultSizePts']; |
||
710 | $r = 0; |
||
711 | |||
712 | foreach ($sheet->Rows->RowInfo as $rowOverride) { |
||
713 | $rowAttributes = $rowOverride->attributes(); |
||
714 | $row = $rowAttributes['No']; |
||
715 | $rowHeight = $rowAttributes['Unit']; |
||
716 | $hidden = ((isset($rowAttributes['Hidden'])) && ($rowAttributes['Hidden'] == '1')) ? true : false; |
||
717 | $rowCount = (isset($rowAttributes['Count'])) ? $rowAttributes['Count'] : 1; |
||
718 | while ($r < $row) { |
||
719 | ++$r; |
||
720 | $spreadsheet->getActiveSheet()->getRowDimension($r)->setRowHeight($defaultHeight); |
||
721 | } |
||
722 | while (($r < ($row+$rowCount)) && ($r < $maxRow)) { |
||
723 | ++$r; |
||
724 | $spreadsheet->getActiveSheet()->getRowDimension($r)->setRowHeight($rowHeight); |
||
725 | if ($hidden) { |
||
726 | $spreadsheet->getActiveSheet()->getRowDimension($r)->setVisible(false); |
||
727 | } |
||
728 | } |
||
729 | } |
||
730 | while ($r < $maxRow) { |
||
731 | ++$r; |
||
732 | $spreadsheet->getActiveSheet()->getRowDimension($r)->setRowHeight($defaultHeight); |
||
733 | } |
||
734 | } |
||
735 | |||
736 | // Handle Merged Cells in this worksheet |
||
737 | if (isset($sheet->MergedRegions)) { |
||
738 | foreach ($sheet->MergedRegions->Merge as $mergeCells) { |
||
739 | if (strpos($mergeCells, ':') !== false) { |
||
740 | $spreadsheet->getActiveSheet()->mergeCells($mergeCells); |
||
741 | } |
||
742 | } |
||
743 | } |
||
744 | |||
745 | $worksheetID++; |
||
746 | } |
||
747 | |||
748 | // Loop through definedNames (global named ranges) |
||
749 | if (isset($gnmXML->Names)) { |
||
750 | foreach ($gnmXML->Names->Name as $namedRange) { |
||
751 | $name = (string) $namedRange->name; |
||
752 | $range = (string) $namedRange->value; |
||
753 | if (stripos($range, '#REF!') !== false) { |
||
754 | continue; |
||
755 | } |
||
756 | |||
757 | $range = explode('!', $range); |
||
758 | $range[0] = trim($range[0], "'"); |
||
759 | if ($worksheet = $spreadsheet->getSheetByName($range[0])) { |
||
760 | $extractedRange = str_replace('$', '', $range[1]); |
||
761 | $spreadsheet->addNamedRange(new \PhpSpreadsheet\NamedRange($name, $worksheet, $extractedRange)); |
||
762 | } |
||
763 | } |
||
764 | } |
||
765 | |||
766 | // Return |
||
767 | return $spreadsheet; |
||
768 | } |
||
769 | |||
770 | private static function parseBorderAttributes($borderAttributes) |
||
771 | { |
||
772 | $styleArray = array(); |
||
841 |
This check marks private properties in classes that are never used. Those properties can be removed.