• Resolved jussitrival

    (@jussitrival)


    I need to get the labels bolded in Excel and I found this code in the FAQ:

    //add this to your functions.php
    add_filter('gfexcel_value_object', function (BaseValue $value, $field, $is_label) {
        // Need to know if this field is a label?
        if (!$is_label) {
            return $value;
        }
    
        $value->setColor('#ffffff'); //font color, needs a six character color hexcode. #fff won't cut it here.
        $value->setBold(true); // Bold text
        $value->setItalic(true); // Italic text (to be combined with bold)
        $value->setBackgroundColor('#0085BA'); // background color
    
        // $field is the GF_Field object, so you can use that too for some checks.
        return $value;
    }, 10, 3);

    After adding that and trying to download the Excel I get this error:

    Error message: Uncaught TypeError: Argument 1 passed to {closure}() must be an instance of BaseValue, instance of GFExcel\Values\StringValue given, called in /var/www/vhosts/mysite/httpdocs/wp-includes/class-wp-hook.php on line 289 and defined in /var/www/vhosts/mysite/httpdocs/wp-content/themes/mytheme/functions.php:8
    Stack trace:
    #0 /var/www/vhosts/mysite/httpdocs/wp-includes/class-wp-hook.php(289): {closure}()
    #1 /var/www/vhosts/mysite/httpdocs/wp-includes/plugin.php(206): WP_Hook->apply_filters()
    #2 /var/www/vhosts/mysite/httpdocs/wp-content/plugins/gravityforms/gravityforms.php(6069): apply_filters()
    #3 /var/www/vhosts/mysite/httpdocs/wp-content/plugins/gf-entries-in-excel/src/Values/BaseValue.php(175): gf_apply_filters()
    #4 /var/www/vhosts/mysite/httpdocs/wp-content/plugins/gf-entries-in-excel/src/Field/AbstractField.php(76): GFExcel\Values\BaseValue::getValueObject()
    #5 [internal function]: 

    I also tried with having only the bold setting there but same error appeared.

    WordPress version 5.5.3
    PHP version 7.4.13
    GF Entries in Excel version 1.8.7
    Gravity Forms version 2.4.21.5

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter jussitrival

    (@jussitrival)

    Ah I actually got it to work by adding this line before the code:

    use GFExcel\Values\BaseValue;

    I found this from another FAQ answer.

    Plugin Author Doeke Norg

    (@doekenorg)

    Ah great that you found the solution. Without the use statement php doesn’t know what you are referring to, so it assumes the global namespace.

    Thanks for letting me know you’ve fixed it!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Error when trying to change style of Excel’ is closed to new replies.