how can I export table content to excel or csv
May the below custom code will helpful for you.

set  the header

$filename= 'export.csv';
  drupal_set_header('Content-Type: text/csv');
  drupal_set_header('Content-Disposition: attachment; filename=' . $filename);


you can write a function(just an example below) by sending the row values, filename, and column title

&lt;?php


function export_to_excel_page($row_array, $filename,$column_titles) {

  drupal_set_header('Content-Type: text/csv');
  drupal_set_header('Content-Disposition: attachment; filename=' . $filename);

  foreach($column_titles as $key =&gt; $value) {
           $keys[] =$value;         
  }

  if($keys) print implode(',', $keys) ."\r\n";
  unset($keys);

    //fetching the field values
  foreach($row_array as $key =&gt; $value) {

   $values[] =$value; 

  }
    print implode(',', $values) ."\r\n";
    unset($values);
    }
    exit;

?&gt;