{strip}
{foreach from=$display_fields item=column name=row}
  {* workaround for an absurd Microsoft Excel problem, in which the first
     two characters of a file cannot be ID; see:
     http://support.microsoft.com/kb/323626 *}
  {if $smarty.foreach.row.first && $column.field_title == "ID"}
    'ID
  {else}
    {$column.field_title|escape:'csv'}
  {/if}
  {if !$smarty.foreach.row.last},{/if}
{/foreach}
{/strip}
{foreach from=$submissions item=submission name=row}{strip}
  {foreach from=$display_fields item=field_info name=col_row}
    {assign var=col_name value=$field_info.col_name}
    {assign var=value value=$submission.$col_name}
    {smart_display_field form_id=$form_id view_id=$view_id
      submission_id=$submission.submission_id field_info=$field_info
      field_types=$field_types settings=$settings value=$value
      escape="csv"}
    {* if this wasn't the last row, output a comma *}
    {if !$smarty.foreach.col_row.last},{/if}
  {/foreach}{/strip}
{if !$smarty.foreach.row.last}
{/if}
{/foreach}