1 of 3
1
Plugin: CSVee
Posted: 02 January 2007 04:54 PM   [ Ignore ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1103
Joined  03-22-2006

Had this code lying around for a bit, and fancied turning it into a plugin for all to use.

Merely add to a blank template like so:

{exp:csvee query="SELECT member_id, username, screen_name, email FROM exp_members"}

Navigate to your template and you should be presented with a downloadable CSV file.

Parameters:

query - The query from which the CSV output is determined.

fixed_width - If you want each column (field) to be a fixed width, supply an integer value in this parameter. By default it will pad those fields that are shorter with spaces. You can change this character with the pad_character parameter.

pad_character - Character used to pad fields that do not meet the fixed width column setting.

seperator - Custom seperator to use between fields. This defaults to a comma.

delimiter - Custom delimiter to encase each field. Defaults to a double quotation. e.g., “My field”

show_headings - Whether to show column headings. possible values are yes or no. Defaults to yes

filename - Desired filename of output file, defaults to “CSVee_Output.csv”

save_path - If you would rather save the output file to disk, use this parameter. You can use this in conjunction with the redirect parameter if you also want to download.

redirect - Where to send the user after visiting the template holding this plugin.

group_id - Pipe delimited ( 1|2|3 ) set of group ID’s if you want to restrict the download to certain member groups.

user_id - Same as above but by user ID.

Important Note:

To use whitespace characters in either of the pad_character/seperator/delimiter parameters just use their literal names, e.g., pad_char=“space” or pad_char=“tab”

Additional:

delete, drop, truncate, update, insert, alter, create

The use of any of these MySql commands will cause the plugin to quit out before issuing the query. This was added for security purposes.

Current Version: 1.1

File Attachments
pi.csvee.zip  (File Size: 3KB - Downloads: 476)
 Signature 

(a.k.a the_butcher)

Profile
 
 
Posted: 04 February 2007 05:27 AM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  873
Joined  05-14-2004

Hey.

I’ve just used this plugin for the first time and it worked really nicely.

Thanks a lot for putting it out there.

Edit to add…

I used the below query

{exp:csvee query="SELECT url_title FROM exp_weblog_titles WHERE weblog_id =18"}

Probably not much use to anyone else.

Profile
 
 
Posted: 23 March 2007 12:24 PM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  785
Joined  07-18-2006

I’ve got a question.  I’m using your plug-in to let the client export data from the FreeForm module (the built-in txt export chokes on a field that allows multiple entries and he doesn’t seem to have any desire to fix it).

CSVee does better, but there’s a small glitch and I’m wondering if it’s possible to fix it, or if it’s just a symptom of opening this file in excel. If you have multiple entries (a field name like this[]) instead of putting line breaks between each value, when you open it in Excel it just has that weird square character it displays for characters it doesn’t understand.  Is it possible to have the line breaks work when opening in Excel?

Thanks (and thanks for sharing the plug-in) smile

Profile
 
 
Posted: 24 March 2007 05:48 AM   [ Ignore ]   [ # 3 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1103
Joined  03-22-2006

Hi Brian,

Not quite sure I understand what is happening, can you send me an example .csv file where this is happening?

 Signature 

(a.k.a the_butcher)

Profile
 
 
Posted: 24 March 2007 01:25 PM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  785
Joined  07-18-2006
the_butcher - 24 March 2007 05:48 AM

Hi Brian,

Not quite sure I understand what is happening, can you send me an example .csv file where this is happening?

Here’s an example - check out the ‘category’ column:

EDIT - it’s not a huge deal, just figured if you knew of an easy fix I’d ask… smile

File Attachments
renewal_submissions.txt  (File Size: 2KB - Downloads: 355)
Profile
 
 
Posted: 25 March 2007 06:58 AM   [ Ignore ]   [ # 5 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1103
Joined  03-22-2006

I do hope those card details are not real :|

 Signature 

(a.k.a the_butcher)

Profile
 
 
Posted: 25 March 2007 07:06 AM   [ Ignore ]   [ # 6 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1103
Joined  03-22-2006

It looks like a character set issue that excel can’t deal with.  I’ve opened the file in OpenOffice and the values show up fine, each on a new line.

Edit add: Are you using excel mac?

 Signature 

(a.k.a the_butcher)

Profile
 
 
Posted: 26 March 2007 08:46 AM   [ Ignore ]   [ # 7 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  785
Joined  07-18-2006

I am on a Mac yes - an old version of Excel (think it’s v.X).

It’s definitely an encoding issue you’re right.  I’m not really sure how to get around it though. If I change the encoding option in the EE general system prefs it doesn’t make a difference (tried ISO-8859-1). Is there a way to force the CSV to use a charset when it is being created?

I’m thinking of using CSVee in another part of the system as well (a conference registration system that allows multiple registrations at once), but it would actually have to honor these line breaks or formatting would get too screwed up to use the CSV…

EDIT - don’t worry - everything in the CSV is fake data - random stuff…

Profile
 
 
Posted: 26 March 2007 12:13 PM   [ Ignore ]   [ # 8 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1103
Joined  03-22-2006

I guess i could make it search for for a CRLF in each column, and replace with just an LF.  Brian, i’ll PM you a newer version.

 Signature 

(a.k.a the_butcher)

Profile
 
 
Posted: 26 March 2007 12:19 PM   [ Ignore ]   [ # 9 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  785
Joined  07-18-2006
the_butcher - 26 March 2007 12:13 PM

I guess i could make it search for for a CRLF in each column, and replace with just an LF.  Brian, i’ll PM you a newer version.

Hey that would be fantastic - thanks a bunch!

Profile
 
 
Posted: 23 April 2007 10:57 PM   [ Ignore ]   [ # 10 ]  
Grad Student
Rank
Total Posts:  76
Joined  02-23-2007

Mmm, is there a version of csvee I can use with EE Core (since Core doesn’t have query module)?

Nevermind, I’ve succesfully export to CSV using PHP.

Profile
 
 
Posted: 24 April 2007 03:13 AM   [ Ignore ]   [ # 11 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1103
Joined  03-22-2006

Csvee doesn’t rely on the query module so you should be able to use this in EE core.

 Signature 

(a.k.a the_butcher)

Profile
 
 
Posted: 24 April 2007 05:27 AM   [ Ignore ]   [ # 12 ]  
Grad Student
Rank
Total Posts:  76
Joined  02-23-2007

Thanx for the reply. I understand now; i thought that query was using the query module.

Profile
 
 
Posted: 27 April 2007 07:06 AM   [ Ignore ]   [ # 13 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  211
Joined  07-30-2002

Any idea if it would be possible to have a parameter to set the delimiter type? One of the fields that I would like to export has a bunch of quote marks in it, and it’s throwing off the importing process.

Thanks,
Jesse

 Signature 

31Three - Creative Services for the Design-Challenged Developer

Profile
 
 
Posted: 27 April 2007 08:28 AM   [ Ignore ]   [ # 14 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1103
Joined  03-22-2006

Sure, will add that in soon… would three extra parameters like:

fixed_width = “x”: where x is number of chars to rpad/cut to
seperator = “tab” / “comma” / “semicolon” / “space” / “custom”: where custom is anything you like
text_delimiter = “single” / “double”: this refers to quotes

suffice?

Edit: I can’t count :D

 Signature 

(a.k.a the_butcher)

Profile
 
 
Posted: 27 April 2007 08:31 AM   [ Ignore ]   [ # 15 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  211
Joined  07-30-2002

Sounds perfect!

 Signature 

31Three - Creative Services for the Design-Challenged Developer

Profile
 
 
Posted: 29 April 2007 08:16 AM   [ Ignore ]   [ # 16 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1103
Joined  03-22-2006

Updated with additional formatting parameters:

fixed_width
pad_character
seperator
delimiter
show_headings

 Signature 

(a.k.a the_butcher)

Profile
 
 
Posted: 30 April 2007 07:12 AM   [ Ignore ]   [ # 17 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  211
Joined  07-30-2002

Awesome! Thanks!

 Signature 

31Three - Creative Services for the Design-Challenged Developer

Profile
 
 
Posted: 28 September 2007 04:36 AM   [ Ignore ]   [ # 18 ]  
Lab Assistant
RankRank
Total Posts:  242
Joined  12-06-2002

Fantastic plugin, thank-you! You’ve probably guessed that flattery precedes a question… any way to have no seperator or delimiter?

Profile
 
 
   
1 of 3
1
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 66475 Total Logged-in Users: 41
Total Topics: 84880 Total Anonymous Users: 21
Total Replies: 455407 Total Guests: 219
Total Posts: 540287    
Members ( View Memberlist )