GravityExport: Splitting complex fields in Multiple Columns
By default, complex fields like the Name, Address, and other fields that contain sub-fields get combined into one column during export. This is often not useful, especially for data analysis.
With the Multiple Columns setting disabled:
|
Entry ID |
Name |
|
1 |
Miss
|
|
2 |
Mr.
|
Notice how all the sub-fields of the Name field are combined into one column.
With the Multiple Columns setting enabled:
|
Entry ID |
Prefix |
First |
Middle |
Last |
Suffix |
|
1 |
Miss |
Alice |
in |
Wonderland |
PhD |
|
2 |
Mr. |
Bob |
Sponge |
Squarepants |
Ms |
When using GravityExport Lite, this setting is available in the GravityExport's Settings tab on the Gravity Forms' Settings page.
Checkbox Fields
The Multiple Columns setting only applies to Name and Address fields by default. If you need to split checkbox fields into separate columns, see How to Export Checkbox Fields as Separate Columns.
Changing the separator character
By default, when the Multiple Columns setting is disabled, sub-field values are combined using line breaks. If you prefer values to be separated by spaces instead (e.g., "Miss Alice in Wonderland PhD" on a single line), you can use the gfexcel_field_value filter to modify the output.
Add this code to your site (learn where to put code samples):
/**
* Replaces line breaks with spaces in exported field values.
*
* When Multiple Columns is disabled, sub-field values are combined using
* line breaks by default. This filter changes the separator to a space.
*
* @param mixed $value The field value being exported.
* @param array $entry The entry being exported.
* @param GF_Field $gf_field The Gravity Forms field object.
*
* @return mixed The modified field value.
*/
add_filter( 'gfexcel_field_value', function( $value, $entry, $gf_field ) {
if ( is_string( $value ) ) {
$value = str_replace( "\n", ' ', $value );
}
return $value;
}, 10, 3 );
This code replaces all line breaks with spaces in exported field values.
With the Multiple Columns setting disabled and the new lines replaced:
|
Entry ID |
Name |
|
1 |
Miss Alice in Wonderland PhD |
|
2 |
Mr. Bob Sponge Squarepants Ms |
You can customize the separator to any character. For example, to use a comma and space:
/**
* Replaces line breaks with spaces in exported field values.
*
* When Multiple Columns is disabled, sub-field values are combined using
* line breaks by default. This filter changes the separator to a space.
*
* @param mixed $value The field value being exported.
* @param array $entry The entry being exported.
* @param GF_Field $gf_field The Gravity Forms field object.
*
* @return mixed The modified field value.
*/
add_filter( 'gfexcel_field_value', function( $value, $entry, $gf_field ) {
if ( is_string( $value ) ) {
$value = str_replace( "\n", ', ', $value );
}
return $value;
}, 10, 3 );
|
Entry ID |
Name |
|
1 |
Miss, Alice, in, Wonderland, PhD |
|
2 |
Mr., Bob, Sponge, Squarepants, Ms |