| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 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 |
?> |
|---|