root/trunk/lib/AkConverters/AkMsExcelToMany.php

Revision 1397, 2.7 kB (checked in by bermi, 6 months ago)

COnverting converters to PHP5

Line 
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 AkMsExcelToMany
20 {
21     public $_file_type_codes = array('csv' => 6,'msdos' => 21,'xls'=>-4143,'rtf'=>6,'unicode'=>7,'doc'=>0,'html'=>8,'txt'=>4);
22
23     public function convert()
24     {
25         $excel = new COM('excel.application') or die('Unable to instantiate Excel');
26         $excel->Visible = false;
27         $excel->WorkBooks->Open($this->source_file);
28         $excel->WorkBooks[1]->SaveAs($this->destination_file,$this->_file_type_codes[$this->convert_to]);
29         $excel->Quit();
30         unset($excel);
31
32         $result = Ak::file_get_contents($this->destination_file);
33         $this->delete_source_file ? @Ak::file_delete($this->source_file) : null;
34         $this->keep_destination_file ? null : Ak::file_delete($this->destination_file);
35
36         return $result;
37     }
38
39     public function init()
40     {
41         $this->ext = empty($this->ext) ? 'xls' : strtolower(trim($this->ext,'.'));
42         $this->tmp_name = Ak::randomString();
43         if(empty($this->source_file)){
44             $this->source_file = AK_TMP_DIR.DS.$this->tmp_name.'.'.$this->ext;
45             Ak::file_put_contents($this->source_file,$this->source);
46             $this->delete_source_file = true;
47             $this->keep_destination_file = empty($this->keep_destination_file) ? (empty($this->destination_file) ? false : true) : $this->keep_destination_file;
48         }else{
49             $this->delete_source_file = false;
50             $this->keep_destination_file = true;
51         }
52
53         $this->convert_to = !empty($this->convert_to) && empty($this->_file_type_codes[$this->convert_to]) ? 'csv' : (empty($this->convert_to) ? 'csv' : $this->convert_to);
54         $this->destination_file_name = empty($this->destination_file_name) ? $this->tmp_name.'.'.$this->convert_to : $this->destination_file_name.(strstr($this->destination_file_name,'.') ? '' : '.'.$this->convert_to);
55         $this->destination_file = empty($this->destination_file) ? AK_TMP_DIR.DS.$this->destination_file_name : $this->destination_file;
56     }
57 }
58
59 ?>
Note: See TracBrowser for help on using the browser.