Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPOffice/PHPExcel GH-558 Check if Styles exist in Excel2003XML file #331

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
218 changes: 110 additions & 108 deletions src/PhpSpreadsheet/Reader/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,137 +423,139 @@ public function loadIntoExisting($pFilename, Spreadsheet $spreadsheet)
}
}

foreach ($xml->Styles[0] as $style) {
$style_ss = $style->attributes($namespaces['ss']);
$styleID = (string) $style_ss['ID'];
$this->styles[$styleID] = (isset($this->styles['Default'])) ? $this->styles['Default'] : [];
foreach ($style as $styleType => $styleData) {
$styleAttributes = $styleData->attributes($namespaces['ss']);
switch ($styleType) {
case 'Alignment':
foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
$styleAttributeValue = (string) $styleAttributeValue;
switch ($styleAttributeKey) {
case 'Vertical':
if (self::identifyFixedStyleValue($verticalAlignmentStyles, $styleAttributeValue)) {
$this->styles[$styleID]['alignment']['vertical'] = $styleAttributeValue;
}
if (isset($xml->Styles)) {
foreach ($xml->Styles[0] as $style) {
$style_ss = $style->attributes($namespaces['ss']);
$styleID = (string)$style_ss['ID'];
$this->styles[$styleID] = (isset($this->styles['Default'])) ? $this->styles['Default'] : [];
foreach ($style as $styleType => $styleData) {
$styleAttributes = $styleData->attributes($namespaces['ss']);
switch ($styleType) {
case 'Alignment':
foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
$styleAttributeValue = (string)$styleAttributeValue;
switch ($styleAttributeKey) {
case 'Vertical':
if (self::identifyFixedStyleValue($verticalAlignmentStyles, $styleAttributeValue)) {
$this->styles[$styleID]['alignment']['vertical'] = $styleAttributeValue;
}

break;
case 'Horizontal':
if (self::identifyFixedStyleValue($horizontalAlignmentStyles, $styleAttributeValue)) {
$this->styles[$styleID]['alignment']['horizontal'] = $styleAttributeValue;
}
break;
case 'Horizontal':
if (self::identifyFixedStyleValue($horizontalAlignmentStyles, $styleAttributeValue)) {
$this->styles[$styleID]['alignment']['horizontal'] = $styleAttributeValue;
}

break;
case 'WrapText':
$this->styles[$styleID]['alignment']['wrapText'] = true;
break;
case 'WrapText':
$this->styles[$styleID]['alignment']['wrapText'] = true;

break;
break;
}
}
}

break;
case 'Borders':
foreach ($styleData->Border as $borderStyle) {
$borderAttributes = $borderStyle->attributes($namespaces['ss']);
$thisBorder = [];
foreach ($borderAttributes as $borderStyleKey => $borderStyleValue) {
switch ($borderStyleKey) {
case 'LineStyle':
$thisBorder['borderStyle'] = Border::BORDER_MEDIUM;
break;
case 'Borders':
foreach ($styleData->Border as $borderStyle) {
$borderAttributes = $borderStyle->attributes($namespaces['ss']);
$thisBorder = [];
foreach ($borderAttributes as $borderStyleKey => $borderStyleValue) {
switch ($borderStyleKey) {
case 'LineStyle':
$thisBorder['borderStyle'] = Border::BORDER_MEDIUM;

break;
case 'Weight':
break;
case 'Position':
$borderPosition = strtolower($borderStyleValue);

break;
case 'Color':
$borderColour = substr($borderStyleValue, 1);
$thisBorder['color']['rgb'] = $borderColour;

break;
}
}
if (!empty($thisBorder)) {
if (($borderPosition == 'left') || ($borderPosition == 'right') || ($borderPosition == 'top') || ($borderPosition == 'bottom')) {
$this->styles[$styleID]['borders'][$borderPosition] = $thisBorder;
}
}
}

break;
case 'Font':
foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
$styleAttributeValue = (string)$styleAttributeValue;
switch ($styleAttributeKey) {
case 'FontName':
$this->styles[$styleID]['font']['name'] = $styleAttributeValue;

break;
case 'Weight':
break;
case 'Position':
$borderPosition = strtolower($borderStyleValue);
case 'Size':
$this->styles[$styleID]['font']['size'] = $styleAttributeValue;

break;
case 'Color':
$borderColour = substr($borderStyleValue, 1);
$thisBorder['color']['rgb'] = $borderColour;
$this->styles[$styleID]['font']['color']['rgb'] = substr($styleAttributeValue, 1);

break;
}
}
if (!empty($thisBorder)) {
if (($borderPosition == 'left') || ($borderPosition == 'right') || ($borderPosition == 'top') || ($borderPosition == 'bottom')) {
$this->styles[$styleID]['borders'][$borderPosition] = $thisBorder;
}
}
}
case 'Bold':
$this->styles[$styleID]['font']['bold'] = true;

break;
case 'Font':
foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
$styleAttributeValue = (string) $styleAttributeValue;
switch ($styleAttributeKey) {
case 'FontName':
$this->styles[$styleID]['font']['name'] = $styleAttributeValue;

break;
case 'Size':
$this->styles[$styleID]['font']['size'] = $styleAttributeValue;

break;
case 'Color':
$this->styles[$styleID]['font']['color']['rgb'] = substr($styleAttributeValue, 1);

break;
case 'Bold':
$this->styles[$styleID]['font']['bold'] = true;

break;
case 'Italic':
$this->styles[$styleID]['font']['italic'] = true;

break;
case 'Underline':
if (self::identifyFixedStyleValue($underlineStyles, $styleAttributeValue)) {
$this->styles[$styleID]['font']['underline'] = $styleAttributeValue;
}
break;
case 'Italic':
$this->styles[$styleID]['font']['italic'] = true;

break;
break;
case 'Underline':
if (self::identifyFixedStyleValue($underlineStyles, $styleAttributeValue)) {
$this->styles[$styleID]['font']['underline'] = $styleAttributeValue;
}

break;
}
}
}

break;
case 'Interior':
foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
switch ($styleAttributeKey) {
case 'Color':
$this->styles[$styleID]['fill']['color']['rgb'] = substr($styleAttributeValue, 1);
break;
case 'Interior':
foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
switch ($styleAttributeKey) {
case 'Color':
$this->styles[$styleID]['fill']['color']['rgb'] = substr($styleAttributeValue, 1);

break;
case 'Pattern':
$this->styles[$styleID]['fill']['fillType'] = strtolower($styleAttributeValue);
break;
case 'Pattern':
$this->styles[$styleID]['fill']['fillType'] = strtolower($styleAttributeValue);

break;
break;
}
}
}

break;
case 'NumberFormat':
foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
$styleAttributeValue = str_replace($fromFormats, $toFormats, $styleAttributeValue);
switch ($styleAttributeValue) {
case 'Short Date':
$styleAttributeValue = 'dd/mm/yyyy';

break;
}
if ($styleAttributeValue > '') {
$this->styles[$styleID]['numberFormat']['formatCode'] = $styleAttributeValue;
break;
case 'NumberFormat':
foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
$styleAttributeValue = str_replace($fromFormats, $toFormats, $styleAttributeValue);
switch ($styleAttributeValue) {
case 'Short Date':
$styleAttributeValue = 'dd/mm/yyyy';

break;
}
if ($styleAttributeValue > '') {
$this->styles[$styleID]['numberFormat']['formatCode'] = $styleAttributeValue;
}
}
}

break;
case 'Protection':
foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
}
break;
case 'Protection':
foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
}

break;
break;
}
}
}
}
Expand Down