tags:

views:

291

answers:

2

hello all,

using php i exported report in excel.But got stuck in merging cells. i want to merge the first 10 cells to dispaly the Name of the Company. The variable which has the company name is in one cell, tried to merge the cells but i cudn't...

can any one help me, thank u in advance.

A: 

I used this function to export,

where $query variable holds the mysql query which is sent as a parameter, and in $fieldname variable, array of fieldnames to display header.

everything is ok, n works properly. one thing i cudn't do was merging cells....

function to_excel_export($query,$fieldName) {

$filename = date('d-m-Y');
 $headers = ''; 
 $data = '';
 $obj =& get_instance();
 if ($query->num_rows() == 0)
 {
      echo '<p>The table appears to have no data.</p>';
 }
 else
 {
     for($i=0;$i<sizeof($fieldName);$i++)
     {
         $headers .= $fieldName[$i] . "\t";
     }

      foreach ($query->result() as $row)
      {
           $line = '';
           foreach($row as $value)
           {                                            
                if ((!isset($value)) OR ($value == ""))
                {
                   $value = "\t";
                } 
                else 
                {
                   $value = str_replace('"', '""', $value);
                   $value = '"' . $value . '"' . "\t";
                }
                $line .= $value;
           }
           $data .= trim($line)."\n";
      }

      $data = str_replace("\r","",$data);
      header("Content-type: application/x-msdownload");
      header("Content-Disposition: attachment; filename=$filename.xls");

      $compName = 'C O M P A N Y - N A M E ';
      echo $compName."\n\n";
      echo $headers."\n".$data; 
 }

}

$compName = 'C O M P A N Y - N A M E ';
      echo $compName."\n\n";

how to merge the cells to display the name which is in $compName variable.

M Y T H
A: 

same here.... have anybody know how to solve this problem.... php mergecell

freddo