Can you share your new EE code that you’re using? Your first example doesn’t output CSV formatted content, just two fields with a line break in-between them.
This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
September 20, 2011 4:36pm
Subscribe [10]#16 / Nov 04, 2011 9:16am
Can you share your new EE code that you’re using? Your first example doesn’t output CSV formatted content, just two fields with a line break in-between them.
#17 / Nov 04, 2011 9:21am
Can you share your new EE code that you’re using? Your first example doesn’t output CSV formatted content, just two fields with a line break in-between them.
I am trying this right now David:
{exp:download_content filename="foo.csv"}
{exp:channel:entries channel="pages" disable="categories|member_data|pagination" dynamic="no"}
{exp:strip_html}
Title, URL Title, Entry ID, Body
{title}, {url_title}, {entry_id}, {simple_content_body}
{/exp:strip_html}
{/exp:channel:entries}
{/exp:download_content}There are two entries in this channel at moment, but there will be a lot more. The simple_content_body is the only one with a long string. It has HTML tags in it so I tried stripping it first but no luck. Can I sent you the generated CSV file?
#18 / Nov 04, 2011 9:22am
Can you share your new EE code that you’re using? Your first example doesn’t output CSV formatted content, just two fields with a line break in-between them.
I took out label row and still no luck.
{exp:download_content filename="foo.csv"}
{exp:channel:entries channel="pages" disable="categories|member_data|pagination" dynamic="no"}
{exp:strip_html}
{title}, {url_title}, {entry_id}, {simple_content_body}
{/exp:strip_html}
{/exp:channel:entries}
{/exp:download_content}#19 / Nov 04, 2011 9:26am
Can you share your new EE code that you’re using? Your first example doesn’t output CSV formatted content, just two fields with a line break in-between them.
It looks like the issue is the commas in the string simple_content_body. How can I get around that issue?
#20 / Nov 04, 2011 9:28am
If any of the content fields have line breaks or commas, which it appears they do, they’ll need to be surrounded in quotes, and any quotes inside the content will need to be properly escaped. e.g.:
"Post Title", "post_title", "4235", "
Sally said, ""Hello there!"" and quickly ran away.
"
#21 / Nov 04, 2011 9:32am
If any of the content fields have line breaks or commas, which it appears they do, they’ll need to be surrounded in quotes, and any quotes inside the content will need to be properly escaped. e.g.:
"Post Title", "post_title", "4235", " Sally said, ""Hello there!"" and quickly ran away. "
The channel I will will eventually be using this with will have hundreds of entries submitted by site visitors. I am just trying to export the entire channel to a CSV file. I will not be able to go through each entry to look for commas or line breaks. Do you have any other suggestions on how I can get past them?
#22 / Nov 04, 2011 9:40am
You don’t have to go through the entries yourself, you can create a plugin that will take the content and make it CSV safe in the output. I think someone already did this though. :-D
#23 / Nov 04, 2011 9:44am
Ah, my mistake, looked too quickly, that plugin is just for custom queries to the database OR all entries and fields from a given channel. If that doesn’t get you up and running, you can take a look at the code from the csv_from_result() method in the DB Utilities CodeIgniter class to use as the basis for a plugin.
#24 / Nov 04, 2011 9:47am
Ah, my mistake, looked too quickly, that plugin is just for custom queries to the database OR all entries and fields from a given channel. If that doesn’t get you up and running, you can take a look at the code from the csv_from_result() method in the DB Utilities CodeIgniter class to use as the basis for a plugin.
Thanks Derek. I will try that. I wish EE have a native way to export to CSV when filtering results in the EDIT view summary page. Possible enhancement?
#25 / Nov 04, 2011 9:58am
Possible plugin, perhaps (there is probably one floating out there already, I didn’t do a thorough search), but one of the beautiful things about ExpressionEngine is that you can fully control the output via your templates; it’s not necessary for any particular output type to be “built in” as it were.
#26 / Nov 04, 2011 10:13am
You don’t have to go through the entries yourself, you can create a plugin that will take the content and make it CSV safe in the output. I think someone already did this though. :-D
I was able to get it working using AJW Export Derek. I wish I could have used the plugin you created, but the comma issue made it break for me. Here is how I did it with AJW Export in case anyone has same issue:
{exp:ajw_export
sql="SELECT
exp_channel_titles.entry_id,
exp_channel_titles.title,
exp_channel_data.field_id_1 AS simple_content_body
FROM exp_channel_titles
INNER JOIN exp_channel_data ON exp_channel_titles.entry_id = exp_channel_data.entry_id
WHERE exp_channel_titles.channel_id = 1"
format="csv" delimter="," filename="foo.csv"}#27 / Nov 04, 2011 10:15am
bgarrant, with AJW Export, couldn’t you have just used the following?
{exp:ajw_export channel="foo" format="csv" filename="foo.csv"}#28 / Nov 04, 2011 10:20am
bgarrant, with AJW Export, couldn’t you have just used the following?
{exp:ajw_export channel="foo" format="csv" filename="foo.csv"}
That exports the entire entry row values including channel id, status, sticky, etc.. I could not find a way limit fields, or to just export the custom fields I created for the channel. All I want to export is the Title, Entry ID and all the custom fields I created. I do not need all the extra stuff. I would love to know if there is an easier way.
#29 / Nov 04, 2011 10:22am
bgarrant, with AJW Export, couldn’t you have just used the following?
{exp:ajw_export channel="foo" format="csv" filename="foo.csv"}
It exports all this when using this method:
"entry_id","site_id","channel_id","author_id","pentry_id","forum_topic_id","ip_address","title","url_title","status","versioning_enabled","view_count_one","view_count_two","view_count_three","view_count_four","allow_comments","sticky","entry_date","dst_enabled","year","month","day","expiration_date","comment_expiration_date","edit_date","recent_comment_date","comment_total","simple_content_body","simple_content_navigation",
"3","1","1","1","0","","127.0.0.1","HOME","home","open","y","0","0","0","0","n","n","1320407721","n","2011","11","04","0","0","20111104115822","0","0","
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
","",
"4","1","1","1","0","","127.0.0.1","OUR COMPANY","our_company","open","y","0","0","0","0","n","n","1320407827","n","2011","11","04","0","0","20111104115808","0","0","
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
","",#30 / Nov 04, 2011 10:27am
I see, thanks for sharing, bgarrant!