how can I export table content to excel or csv I am using drupal 6, I have created a table using  

$tableHeader = array (     
  array('data' =&gt; 'Ebooks','field' =&gt; 'etitle'),
  array('data' =&gt; 'Volumes','field' =&gt; 'Volume' ),        
  array('data' =&gt; 'Chapter','field' =&gt; 'ctitle'),
  array('data' =&gt; 'Total Sale'),
);

$TableRows[] = array (
  l($row-&gt;etitle,$ebookinfo),
  $row-&gt;name,                              
  str_replace("&amp;amp;", "&amp;" ,$row-&gt;ctitle ),                             
  round($row-&gt;totalsale,2).' $',
); 

$output .= theme('table', $tableHeader, $TableRows);// get the pager
$output .= theme('pager', NULL, 5, 0);


How can I export it to MS 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;