[ Index ]

PHP Cross Reference of Akelos Framework

title

Body

[close]

/AkConverters/ -> AkExcelToArray.php (source)

   1  <?php
   2  /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
   3  
   4  // +----------------------------------------------------------------------+
   5  // | Akelos Framework - http://www.akelos.org                             |
   6  // +----------------------------------------------------------------------+
   7  // | Copyright (c) 2002-2006, Akelos Media, S.L.  & Bermi Ferrer Martinez |
   8  // | Released under the GNU Lesser General Public License, see LICENSE.txt|
   9  // +----------------------------------------------------------------------+
  10  
  11  /**
  12   * @package ActiveSupport
  13   * @subpackage Converters
  14   * @author Bermi Ferrer <bermi a.t akelos c.om>
  15   * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org
  16   * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html>
  17   */
  18  
  19  class AkExcelToArray
  20  {
  21      function convert()
  22      {
  23          $this->handler->read($this->source_file);
  24          
  25          $result = array();
  26          for ($i = 1; $i <= $this->handler->sheets[0]['numRows']; $i++) {
  27              if($i === 1){
  28                  @$col_names = $this->handler->sheets[0]['cells'][$i-1];
  29                  foreach (range(1, $this->handler->sheets[0]['numCols']) as $column_number){
  30                      $col_names[$column_number-1] = empty($col_names[$column_number-1]) ? $column_number : trim($col_names[$column_number-1],"\t\n\r ");
  31                  }
  32                  continue;
  33              }
  34  
  35              for ($j = 0; $j < $this->handler->sheets[0]['numCols']; $j++) {
  36                  $result[$i-2][$col_names[$j]] = isset($this->handler->sheets[0]['cells'][$i-1][$j]) ? $this->handler->sheets[0]['cells'][$i-1][$j] : null;
  37              }
  38          }
  39          $this->delete_source_file ? @Ak::file_delete($this->source_file) : null;
  40          return $result;
  41      }
  42  
  43      function init()
  44      {
  45          if(empty($this->handler)){
  46              require_once(AK_VENDOR_DIR.DS.'Excel'.DS.'reader.php');
  47              $this->handler = new Spreadsheet_Excel_Reader();
  48              $this->handler->setRowColOffset((empty($this->first_column) ? 0 : $this->first_column));
  49          }
  50          
  51          $this->tmp_name = Ak::randomString();
  52          if(empty($this->source_file)){
  53              $this->source_file = AK_TMP_DIR.DS.$this->tmp_name.'.xls';
  54              Ak::file_put_contents($this->source_file,$this->source);
  55              $this->delete_source_file = true;
  56              $this->keep_destination_file = empty($this->keep_destination_file) ? (empty($this->destination_file) ? false : true) : $this->keep_destination_file;
  57          }else{
  58              $this->delete_source_file = false;
  59              $this->keep_destination_file = true;
  60          }
  61      }
  62  }
  63  
  64  ?>


Generated: Mon Oct 27 12:43:49 2008 Cross-referenced by PHPXref 0.6