<?php
//generate an excel spread sheet

// Include PEAR::Spreadsheet_Excel_Writer
  
require_once "Spreadsheet/Excel/Writer.php";

// Create an instance
$xlsfile = "sheet".date("ymdhi").".xls";
$xls =& new Spreadsheet_Excel_Writer($xlsfile);
//formats
//multiple line
$MLineFormat = &$xls->addFormat(array('Align'=>'center', 'vAlign' => 'top'));
$MLineFormat->setTextWrap();
//bold
$BoldFormat = &$xls->addFormat(array('vAlign' => 'top'));
$BoldFormat->setBold();
//multiple line bold
$MLineBoldFormat = &$xls->addFormat(array('Align'=>'center', 'vAlign' => 'top'));
$MLineBoldFormat->setTextWrap();
$MLineBoldFormat->setBold();

function
simple_header($header, $j0=0, $i0=0) {
  
//this generates a simple sheet header, column & row offset optional
  
global $sheet, $BoldFormat;
  if(!empty(
$header)) {
    for(
$j=$j0; $j<$j0+count($header);$j++) {
      
$sheet->write($i0,$j,$header[$j], $BoldFormat);  
    }
  }
}

function
simple_row($data, $keys, $i0, $j0=0) {
  
//enter the ith row
  
global $sheet;
  
$j = $j0;
  for(
$k = 0; $k < count($keys); $k++) {
    if(isset(
$data[$keys[$k]])) {
      
$sheet->write($i0, $j, $data[$keys[$k]]);
    }
    
$j++;
  }
}

?>
1