Example #1
0
 function render_validation($id, array $address = null)
 {
     $sheets_name = $this->sheets_name();
     $validation = $this->validations[$id];
     if (array_key_exists('TABLE:CONDITION', $validation['attrs'])) {
         $temp_validation = str_replace('$', '', $validation['attrs']['TABLE:CONDITION']);
         $temp_validation_pieces = explode(":", $temp_validation, 2);
         $temp_validation = $temp_validation_pieces[1];
     } else {
         $temp_validation = "";
     }
     if (preg_match('/cell-content-is-in-list/', $temp_validation)) {
         // si validation de type "list de valeurs"
         preg_match_all("/cell-content-is-in-list\\((.*)\\)/", $temp_validation, $matches);
         $values = $matches[1][0];
         $temp_car = str_split($values);
         if ($temp_car[0] == '[') {
             // Range de valeurs
             $values = str_replace(array('[', ']'), '', $values);
             $values = explode(":", $values, 2);
             $head = OpenFormulaParser::referenceToCoordinates($values[0], 0, $sheets_name);
             $tail = OpenFormulaParser::referenceToCoordinates($values[1], $head[0], $sheets_name);
             $values = array();
             for ($i = 0; $i <= $tail[1] - $head[1]; $i++) {
                 for ($j = 0; $j <= $tail[2] - $head[2]; $j++) {
                     $tmp_sI = $head[0];
                     $tmp_rI = $head[1] + $i;
                     $tmp_cI = $head[2] + $j;
                     $tempcell = $this->tool_get_cell($tmp_sI, $tmp_rI, $tmp_cI);
                     if ($tempcell) {
                         $values[] = $tempcell->cell_get_value();
                     }
                 }
             }
         } else {
             $values = array();
             // Value list
             $validation_values = explode(";", $matches[1][0]);
             // Clean list
             foreach ($validation_values as $tmp_value) {
                 // Remove first and last chars, that are both "
                 $values[] = substr($tmp_value, 1, -1);
             }
         }
         // Set the list of potential values in the cell (adress)
         if (isset($address)) {
             $tmp_sI = $address[0];
             $tmp_rI = $address[1];
             $tmp_cI = $address[2];
         } else {
             $head = OpenFormulaParser::referenceToCoordinates($validation['attrs']['TABLE:BASE-CELL-ADDRESS'], 0, $sheets_name);
             $tmp_sI = $head[0];
             $tmp_rI = $head[1];
             $tmp_cI = $head[2];
         }
         $tempcell = $this->sheets[$tmp_sI]->row[$tmp_rI]->cells[$tmp_cI];
         $tempcell->setValueInList($values);
     }
 }
Example #2
0
 function orderData()
 {
     $sheetsNames = array();
     foreach ($this->sheets as $currentSheetIndex => $sheet) {
         $name = $sheet['TABLE:NAME'];
         /**
          * Sheet name with just a dot
          */
         if ($name == '.') {
             $name = "'" . $name . "'";
         }
         $sheetsNames[] = $name;
     }
     foreach ($this->sheets as $currentSheetIndex => $sheet) {
         $this->spreadsheet->addSheet($currentSheetIndex, htmlentities($sheet['TABLE:NAME'], ENT_QUOTES, "UTF-8"));
         if (array_key_exists('column', $sheet)) {
             foreach ($sheet['column'] as $curCOLI => $col) {
                 $tempcol = new Column($curCOLI);
                 if (array_key_exists('attrs', $col)) {
                     if (array_key_exists('TABLE:STYLE-NAME', $col['attrs'])) {
                         $tempcol->addStyle($col['attrs']['TABLE:STYLE-NAME']);
                     }
                     if (array_key_exists('TABLE:VISIBILITY', $col['attrs'])) {
                         if ($col['attrs']['TABLE:VISIBILITY'] == 'collapse') {
                             $tempcol->collapse();
                         }
                     }
                     if (array_key_exists('TABLE:DEFAULT-CELL-STYLE-NAME', $col['attrs'])) {
                         $tempcol->col_set_default_cell_style($col['attrs']['TABLE:DEFAULT-CELL-STYLE-NAME']);
                     }
                 }
                 $this->addCol($currentSheetIndex, $tempcol);
             }
         }
         if (array_key_exists('rows', $sheet)) {
             foreach ($sheet['rows'] as $cR => $row) {
                 $row_options = array();
                 if (array_key_exists('attrs', $row)) {
                     if (array_key_exists('TABLE:STYLE-NAME', $row['attrs'])) {
                         $row_options['style'] = htmlentities($row['attrs']['TABLE:STYLE-NAME'], ENT_QUOTES, "UTF-8");
                     }
                     if (array_key_exists('TABLE:VISIBILITY', $row['attrs'])) {
                         $row_options['collapse'] = $row['attrs']['TABLE:VISIBILITY'] == 'collapse';
                     }
                     if (array_key_exists('TABLE:STYLE-NAME', $row['attrs'])) {
                         $row_options['style'] = $row['attrs']['TABLE:STYLE-NAME'];
                     }
                 }
                 $this->addRow($currentSheetIndex, $cR, $row_options);
                 if (array_key_exists('cells', $row)) {
                     // If there are cells in the row
                     foreach ($row['cells'] as $cC => $cell) {
                         $cell_options = array();
                         if (array_key_exists('attrs', $cell)) {
                             if (array_key_exists('TABLE:NUMBER-ROWS-SPANNED', $cell['attrs'])) {
                                 $cell_options['rowspan'] = $cell['attrs']['TABLE:NUMBER-ROWS-SPANNED'];
                             }
                             if (array_key_exists('TABLE:NUMBER-COLUMNS-SPANNED', $cell['attrs'])) {
                                 $cell_options['colspan'] = $cell['attrs']['TABLE:NUMBER-COLUMNS-SPANNED'];
                             }
                             if (array_key_exists('TABLE:STYLE-NAME', $cell['attrs'])) {
                                 $cell_options['style'] = strtolower($cell['attrs']['TABLE:STYLE-NAME']);
                             } else {
                                 if ($default_style = $this->getColDefaultCellStyle($currentSheetIndex, $cC)) {
                                     $cell_options['style'] = strtolower($default_style);
                                 }
                             }
                             if (array_key_exists('OFFICE:VALUE', $cell['attrs'])) {
                                 $cell_options['value_attr'] = htmlentities($cell['attrs']['OFFICE:VALUE'], ENT_QUOTES, "UTF-8");
                             }
                             if (array_key_exists('OFFICE:BOOLEAN-VALUE', $cell['attrs'])) {
                                 $cell_options['value_attr'] = htmlentities($cell['attrs']['OFFICE:BOOLEAN-VALUE'], ENT_QUOTES, "UTF-8");
                             }
                             if (array_key_exists("OFFICE:VALUE-TYPE", $cell['attrs'])) {
                                 $cell_options['value_type'] = $cell['attrs']['OFFICE:VALUE-TYPE'];
                             }
                             if (array_key_exists("TABLE:CONTENT-VALIDATION-NAME", $cell['attrs'])) {
                                 $cell_options['validation'] = $cell['attrs']["TABLE:CONTENT-VALIDATION-NAME"];
                             }
                             if (array_key_exists("TABLE:FORMULA", $cell['attrs'])) {
                                 $openFormula = $cell['attrs']['TABLE:FORMULA'];
                                 $cellCoordinates = [$currentSheetIndex, $cR, $cC];
                                 $formula = OpenFormulaParser::parse($openFormula, $currentSheetIndex, $sheetsNames, $cellCoordinates);
                                 if ($formula->isPrintable()) {
                                     $this->spreadsheet->addFormula($formula);
                                 }
                                 $cell_options['type'] = "out";
                             }
                         }
                         if (array_key_exists('value', $cell)) {
                             $cell_options['value_disp'] = $cell['value'];
                         }
                         if (array_key_exists('annotation', $cell)) {
                             $cell_options['annotation'] = $cell['annotation'];
                         }
                         $this->addCell($currentSheetIndex, $cR, $cC, $cell_options);
                     }
                 }
             }
         }
     }
 }