1. Huubss
  2. RO CSVI
  3. Saturday, 05 August 2023
  4.  Subscribe via email
I have XLSX export and i want the quanitity field to set to a color if the amount is higher than 1. I tried setting the helper export with this code, but it's not working.. Porbably because the field doesnt have a value?

/**
* Get styles set for each field in template fields
*
* @param object $field Field to process styles
*
* @return array
*
* @since 8.8.0
*/
private function getFieldStyles(object $field): array
{
$horizontalAlignment = '';
$verticalAlignment = '';
$bold = false;
$italic = false;
$sheetFont = $this->template->get('sheet_font', 'Arial');




if ($field->font_style)
{
switch ($field->font_style)
{
case 'bold':
$bold = true;
break;
case 'italic':
$italic = true;
break;
case 'bold italic':
$bold = true;
$italic = true;
break;
}
}

if ($field->align_horizontal)
{
$horizontalAlignment = $this->getHorizontalAlignment($field->align_horizontal);
}

if ($field->align_vertical)
{
$verticalAlignment = $this->getVerticalAlignment($field->align_vertical);
}

$styleArray['font'] =
[
'name' => $field->column_font ?? $sheetFont,
'bold' => $bold,
'italic' => $italic,
'size' => $field->font_size ?: 12,
'color' => [
'rgb' => $field->column_color ? substr($field->column_color, 1) : ''
]
];

if ($horizontalAlignment && $verticalAlignment)
{
$styleArray['alignment'] =
[
$horizontalAlignment,
$verticalAlignment,
];
}

if ($field->column_background)
{
$styleArray['fill'] =
[
'fillType' => Fill::FILL_SOLID,
'startColor' => [
'argb' => substr($field->column_background, 1),
],
'endColor' => [
'argb' => substr($field->column_background, 1),
]
];
}

if($field->column_header == "Aantal"){

if((int)$field->cdata > 1){
$styleArray['fill'] =
[
'fillType' => Fill::FILL_SOLID,
'startColor' => [
'argb' => "fff81f",
],
'endColor' => [
'argb' => "fff81f",
]
];
}
}

return $styleArray ?? [];
}
Accepted Answer
Accepted Answer Pending Moderation
Hello,
In the helper file you are editing on line 251 inside prepareContent method we call the method getFieldStyles. The variable $value inside prepareContent method has the field value. You need to pass this variable as args into getFieldStyles method and modify your code based on that. Check if that works for you.
Kind regards,

Tharuna

=========================
If you use our extensions, please post a rating and a review at the Joomla! Extension Directory
  1. more than a month ago
  2. RO CSVI
  3. # Permalink
Accepted Answer Pending Moderation
Hello,
In the condition to check if value is greater than 1, you have used cdata use value instead like below. Check is export works as expected.


if($field->column_header == "Aantal"){

if((int)$field->value > 1){
$styleArray['fill'] =
[
'fillType' => Fill::FILL_SOLID,
'startColor' => [
'argb' => "fff81f",
],
'endColor' => [
'argb' => "fff81f",
]
];
}
}
Kind regards,

Tharuna

=========================
If you use our extensions, please post a rating and a review at the Joomla! Extension Directory
  1. more than a month ago
  2. RO CSVI
  3. # 1
Accepted Answer Pending Moderation
Yeah i changed that to cdata because value isn't working. Just tested it and it does not work indeed. Seems that the value field is not getting filled properly. There is no valeu in the ->value field.
  1. more than a month ago
  2. RO CSVI
  3. # 2
Accepted Answer Pending Moderation
Hello,
In the helper file you are editing on line 251 inside prepareContent method we call the method getFieldStyles. The variable $value inside prepareContent method has the field value. You need to pass this variable as args into getFieldStyles method and modify your code based on that. Check if that works for you.

You are a life saver. Thanks again for the great help! Really appreciate it!
  1. more than a month ago
  2. RO CSVI
  3. # 3
  • Page :
  • 1


There are no replies made for this post yet.
Be one of the first to reply to this post!