• Hi there,

    I have a question about formatting the Excel file based on the content of my form, I am trying to replicate the layout in the linked screen grab below.

    In my form I have 3 sections, and would like to be able to output each section as a row in Excel with the Section headings as the row title (column 1) and the form fields in separate columns with the field name in column titles (each section has the same 5 entries)

    Please see linked screen grab for required layout of Excel file (shaded formatting is not an issue).

    https://cln.sh/Vn9Kr3aCkvmMpkNk7t0y

    Hope that makes sense.

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

    (@doekenorg)

    Hi @cpfusion,

    Wew, that’s a tall order ??

    From where I’m sitting this would only make sense for a single entry, right?

    What you could do is use gfexcel_output_rows to change the content of the rows, and gfexcel_output_columns to change the content of the headings.

    I think you need to do the following:

    – use gfexcel_output_columns to:
    1. Add a column to the front containing Financial Forecast (using array_unshift)
    2. Remove every column after the sixth column. (using array_slice($columns, 0, 5), 5 because an array is 0-indexed, so that would make 6 columns).

    – use gfexcel_output_rows split up every row into multiple rows. I can’t really give you an exact code, because I don’t have your form. But you can loop over every column while counting, and make a new row when you hit a number divisible by 6. Something like this (very quick, untested and ugly code, sorry ;-)):

    add_filter('gfexcel_output_rows_<form_id>', function (array $rows): array {
        $new_rows = [];
    
        // Loop all rows
        foreach ($rows as $row) {
            $i = 0;
            $new_row = [];
            // Loop every column
            foreach ($row as $column) {
                $i++;
    
                $new_row[] = $column;
                // divisible by 6
                if ($i % 6 === 0) {
                    $new_rows[] = $new_row; // add new row
                    $i = 0; // reset counter
                    $new_row = []; // reset new row
                }
            }
            if (count($new_row) > 0) {
                // add last row if needed
                $new_rows[] = $new_row;
            }
        }
    
        return $new_rows;
    });

    I hope this helps you out. If not, please contact me on [email protected]. We might be able to work something out.

    Thread Starter Craig

    (@cpfusion)

    Hi Doeke,

    Thank you very much for the detailed response. And, yes, it is for a single entry.

    I thought it may be less than straight forward. I shall endeavour to give this a try, and let you know how it goes.

    Best regards,
    Craig

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Start new row in Excel file with a new section in Gravity Form’ is closed to new replies.