예제 #1
0
파일: grid.php 프로젝트: linuxwhy/tiki-1
 function _load(TikiSheet &$sheet)
 {
     $document = new Spreadsheet_Excel_Reader();
     if (!$document->read($this->file)) {
         return false;
     }
     $data = $document->sheets[0];
     if (is_array($data['cells'])) {
         foreach ($data['cells'] as $row => $cols) {
             if (is_array($cols)) {
                 foreach ($cols as $col => $value) {
                     $sheet->initCell($row, $col);
                     $info = $data['cellsInfo'][$row][$col];
                     if (!isset($info['rowspan'])) {
                         $height = 1;
                     } else {
                         $height = $info['rowspan'];
                     }
                     if (!isset($info['colspan'])) {
                         $width = 1;
                     } else {
                         $width = $info['colspan'];
                     }
                     $cellValue = $this->encoding->convert_encoding($value);
                     $sheet->setValue($cellValue);
                     if (isset($cellValue)) {
                         if (strlen($cellValue)) {
                             if ($cellValue[0] == '=') {
                                 $sheet->setCalculation(substr($cellValue, 1));
                             } else {
                                 $sheet->setCalculation($cellValue);
                             }
                         }
                     }
                     $sheet->setSize($width, $height);
                 }
             }
         }
     }
     return true;
 }
예제 #2
0
 function _load(TikiSheet &$sheet)
 {
     $d = $this->data;
     $rows = (int) $d->metadata->rows;
     $cols = (int) $d->metadata->columns;
     for ($r = 0; $r < $rows; $r++) {
         for ($c = 0; $c < $cols; $c++) {
             $ri = 'r' . $r;
             $ci = 'c' . $c;
             if (isset($d->data->{$ri}->{$ci}->value)) {
                 $val = $d->data->{$ri}->{$ci}->value;
             } else {
                 $val = '';
             }
             $sheet->initCell($r, $c);
             if (isset($d->data->{$ri}->{$ci}->width) || isset($d->data->{$ri}->{$ci}->height)) {
                 $sheet->setSize(isset($d->data->{$ri}->{$ci}->width) ? $d->data->{$ri}->{$ci}->width : 1, isset($d->data->{$ri}->{$ci}->height) ? $d->data->{$ri}->{$ci}->height : 1);
             } else {
                 $sheet->setSize(1, 1);
             }
             $sheet->setValue($val);
             if (isset($d->data->{$ri}->{$ci}->formula)) {
                 $formula = substr($d->data->{$ri}->{$ci}->formula, 1, strlen($d->data->{$ri}->{$ci}->formula) - 1);
                 if (!empty($formula)) {
                     $sheet->setCalculation($formula);
                 }
             }
             if (isset($d->data->{$ri}->{$ci}->stl)) {
                 $style = $d->data->{$ri}->{$ci}->stl;
                 if (!empty($style)) {
                     $sheet->setStyle($style);
                 }
             }
             if (isset($d->data->{$ri}->{$ci}->cl)) {
                 $class = $d->data->{$ri}->{$ci}->cl;
                 if (!empty($class)) {
                     $sheet->setClass($class);
                 }
             }
         }
     }
     return true;
 }