|
Revision 1397, 2.6 kB
(checked in by bermi, 6 months ago)
|
COnverting converters to PHP5
|
| Line | |
|---|
| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class AkExcelToArray |
|---|
| 20 |
{ |
|---|
| 21 |
public 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 |
public 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 |
?> |
|---|