Support

Home Forums Event Espresso Premium File CSV

File CSV

Posted: October 5, 2016 at 9:28 pm

Viewing 8 reply threads


Cod106

October 5, 2016 at 9:28 pm

Hello,

I have a problem with the export (CSV) of my clients list for a lecon.
When I export the file all work but information are separate by , and excel need ; . Who I can change this in the file php?

Thanks


Tony

  • Support Staff

October 6, 2016 at 5:03 am

Hi Olivier,

The delimiter used within CSV is filterable which means you change it using a function.

Here is an example of how to change it to use a semi-colon:

https://github.com/eventespresso/ee-code-snippet-library/blob/master/admin/tw_ee_set_csv_delimiter.php

That function is within a plugin but you could also just ad that to your themes functions.php file or create your own Custom Functions Plugin and add the function to that.


Cod106

October 6, 2016 at 11:33 pm

OK great good update thanks.

An other question some caracters like (é à ò) in french are not good it’s possible to format the export with UTF8?


Tony

  • Support Staff

October 7, 2016 at 3:32 am

What program are you opening the CSV within?

For excel, take a look here:

http://stackoverflow.com/questions/6002256/is-it-possible-to-force-excel-recognize-utf-8-csv-files-automatically


Cod106

October 11, 2016 at 12:00 am

Hello,

ON my php file i have this code but the order not stay like this:

How i can have the same order?
And how i can delete this row Transaction Promotions, i not need?

Thanks

Example on the export order:

Transaction Etat
Prénom[ATT_fname]
Nom[ATT_lname]
Téléphone[ATT_phone]
Titre – System Question
Localite
Adresse
npa
Date de naissance
Transaction Promotions

CODE PHP

<?php
/*
Plugin Name: Fichecod106
Description: Creation de fiche de cours pour cod106
*/
/* Begin Adding Functions Below This Line; Do not include an opening PHP tag as this sample code already includes one! */
//only include these 4 columns in the registration CSV output

add_filter( 'FHEE__EE_Export__report_registrations__reg_csv_array', 'espresso_reg_report_filter_columns', 10, 2);
function espresso_reg_report_filter_columns( $csv_row, $registration_db_row ) {
    $filtered_csv_row = array_intersect_key(
            $csv_row,
            array_flip( array(
	
		__( 'Prénom[ATT_fname]', 'event_espresso' ),
		__( 'Nom[ATT_lname]', 'event_espresso' ),
		__( 'Adresse' ),
		__( 'npa' ),
		__( 'Localite' ),
		__( 'l&eacute', 'event_espresso'  ),
		__( 'Date de naissance', 'event_espresso' ),
		__( 'Titre - System Question', 'event_espresso' ),
		__('Transaction Etat', 'event_espresso'),
		__('T&eacute;l&eacute;phone[ATT_phone]', 'event_espresso'),
	
		
		
		

		
		
		
	
		
		//custom question's admin label, doesn't need to be translated. note though: if you ever change the custom question's admin label, this code will need to be adjusted
				) ) );
	return $filtered_csv_row;
}

function tw_ee_set_csv_delimiter( $delimiter ) {
	
	//Change the CSV delimited/seperator to be a semi colon.
	$delimiter = ';';
	return $delimiter;
}
add_filter( 'FHEE__EE_CSV__fputcsv2__delimiter', 'tw_ee_set_csv_delimiter' );

/* Stop Adding Functions */


Cod106

October 14, 2016 at 8:26 am

You not answer me abaout the order, Why?

URGENT thanks a lot


Tony

  • Support Staff

October 17, 2016 at 6:55 am

Hi there,

array_intersect_key() which that functions uses does not alter the order of the CSV at all. It simply looks in the array and returns the values for keys that match what you have set.

You need a different function when you want to change the order, we have an example here:

https://github.com/eventespresso/ee-code-snippet-library/blob/master/admin/tw_ee_registration_report_limit_columns_shown.php

And how i can delete this row Transaction Promotions, i not need?

The promotions add-on hooks into the same hook used above and uses priority 10, to remove it you want the above function to always run AFTER the promotions add-on has added its fields, so change the priority to something like 20.

add_filter( 'FHEE__EE_Export__report_registrations__reg_csv_array', 'espresso_reg_report_filter_columns', 20, 2);


Cod106

October 18, 2016 at 4:09 pm

Thanks a lot is working.

Just I have a bug again with the signes like
Pr√©nom[ATT_fname] normally is Prénom
Lo√Øc normally is Loïc
Whats the function to force to export the csv in utf8???

It’s possible to put color in the columb when you export the csv?

See my csv.

<?php

function tw_ee_espresso_reg_report_filter_columns_ordered( $csv_row, $registration_db_row ) {

	//Set the allowed fields here and also set them in the order you want them to be displayed within the CSV
	$allowed_fields_in_order = array(
	 __( 'Titre - System Question', 'event_espresso' ),
		__( 'Prénom[ATT_fname]', 'event_espresso' ),
		__( 'Nom[ATT_lname]', 'event_espresso' ),
		__( 'Adresse' ),
		__( 'npa' ),
		__( 'Localite' ),
		__('T&eacute;l&eacute;phone[ATT_phone]', 'event_espresso'),
		__( 'Date de naissance', 'event_espresso' ),
		__('Transaction Etat', 'event_espresso'),
	);

	//Sets $filtered_csv_row to only contain the 'allowed' fields.
	$filtered_csv_row = array_intersect_key(
			$csv_row,
			array_flip( $allowed_fields_in_order ) 
		);
	
	//Now lets set $filtered_csv_row to use the same custom order we set $allowed_fields_in_order to
	$filtered_csv_row = array_merge(array_flip($allowed_fields_in_order), $filtered_csv_row );

	return $filtered_csv_row;
	
	
}

function tw_ee_set_csv_delimiter( $delimiter ) {
	
	//Change the CSV delimited/seperator to be a semi colon.
	$delimiter = ';';
	return $delimiter;
}

add_filter( 'FHEE__EE_CSV__fputcsv2__delimiter', 'tw_ee_set_csv_delimiter' );

/* Stop Adding Functions */
add_filter( 'FHEE__EE_Export__report_registrations__reg_csv_array', 'tw_ee_espresso_reg_report_filter_columns_ordered', 20, 2);


Josh

  • Support Staff

October 19, 2016 at 10:57 am

Hi Olivier,

I don’t think that will work to translate the columns name in the code. I remember that it needs the original text strings in the filter function in order to return the correct values.

To your question about doing a CSV in UTF-8, there’s some ideas in this stack exchange thread:

http://stackoverflow.com/questions/4348802/how-can-i-output-a-utf-8-csv-in-php-that-excel-will-read-properly

Viewing 8 reply threads

The support post ‘File CSV’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso