• Resolved manelg0

    (@manelguillenp)


    Hello, congratulations on the work, great complement.

    My question is, is it possible to add an additional field to the exported .xlsx file that shows only the filename of the uploaded images. That is, in the exported file two fields appear, the path of the image and only the name of the file.

    thanks for your help, greetings

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Doeke Norg

    (@doekenorg)

    Hi @manelguillenp,

    Sorry for the late response. This ticket slipped by me.

    It is possible, but it does take some work. Your best option is to overwrite the FileUploadField transformer with a custom implementation. Something like this should do the trick:

    class FileNameUploadField extends \GFExcel\Field\FileUploadField
    {
        // Duplicate the field paths to another cell and only return the base name.
        public function getCells($entry)
        {
            if ($cells = parent::getCells($entry)) {
                $base_name = implode(' , ', array_map('basename', explode(' , ', $cells[0])));
                $cells = array_merge($cells, $this->wrap([$base_name]));
            }
    
            return $cells;
        }
    
        // Add another cell that only contains the filename. Will have the same name with <code>(filename)</code> attached to the label.
        public function getColumns()
        {
            if ($columns = parent::getColumns()) {
                $columns = array_merge($columns, $this->wrap([$columns[0] . ' (filename)'], true));
            }
    
            return $columns;
        }
    }
    
    // Replace the regular fileupload transformer with the custom implementation.
    add_filter('gfexcel_transformer_fields', function (array $fields) {
        $fields['fileupload'] = FileNameUploadField::class;
    
        return $fields;
    });

    I would recommend storing the class in a separate file and include that inside your functions.php.

    Hope this helps you out. Let me know if it did, or if you need any help!

    Plugin Author Doeke Norg

    (@doekenorg)

    closed due to inactivity. If you have any further questions; please let me know!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Additional export field in uploaded images’ is closed to new replies.