Example #1
0
 /**
  * 
  * @param DOMElement $element
  * @return PHPExcel_Cell
  */
 protected function _addCell($element, $row = null)
 {
     $text = trim($element->nodeValue);
     $cell = $this->_mainSheet->getCellByColumnAndRow($this->_currentCell, $this->_currentRow);
     if (preg_match('/^\\$ *(\\d{1,3}(\\,\\d{3})*|(\\d+))(\\.\\d{2})?$/', $text)) {
         $currencyCode = PHPExcel_Shared_String::getCurrencyCode();
         $decimalSeparator = PHPExcel_Shared_String::getDecimalSeparator();
         $thousandsSeparator = PHPExcel_Shared_String::getThousandsSeparator();
         $value = (double) trim(str_replace(array($currencyCode, $thousandsSeparator, $decimalSeparator), array('', '', '.'), $text));
         $cell->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_NUMERIC);
         //Style
         $cell->getWorksheet()->getStyle($cell->getCoordinate())->getNumberFormat()->setFormatCode(str_replace('$', $currencyCode, PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE));
     } else {
         $cell->setValueExplicit($text, PHPExcel_Cell_DataType::TYPE_STRING);
     }
     $currentCell = $this->_currentCell;
     if ($element->hasAttribute('colspan')) {
         $colspan = (int) $element->getAttribute('colspan');
         $cellTarget = $this->_currentCell + $colspan - 1;
         $this->_mainSheet->mergeCellsByColumnAndRow($this->_currentCell, $this->_currentRow, $cellTarget, $this->_currentRow);
         $this->_currentCell += $colspan;
     } else {
         $this->_currentCell++;
     }
     if ($element->hasAttribute('rowspan')) {
         $rowSpan = (int) $element->getAttribute('rowspan');
         if ($rowSpan < 2) {
             return $cell;
         }
         $rowTarget = $this->_currentRow + ($rowSpan - 1);
         $this->_mainSheet->mergeCellsByColumnAndRow($currentCell, $this->_currentRow, $currentCell, $rowTarget);
     }
     return $cell;
 }
Example #2
0
 /**
  * Merges the area given by its arguments.
  *
  * @param integer $first_row First row of the area to merge
  * @param integer $first_col First column of the area to merge
  * @param integer $last_row  Last row of the area to merge
  * @param integer $last_col  Last column of the area to merge
  */
 public function merge_cells($first_row, $first_col, $last_row, $last_col)
 {
     $this->worksheet->mergeCellsByColumnAndRow($first_col, $first_row + 1, $last_col, $last_row + 1);
 }
Example #3
0
 /**
  * Método que gera a planilha de evolução anual por unidade e ano
  */
 public function evolucaoAnual()
 {
     //Inicializando os filtros usados na página
     $this->filtro->initGets(array("unidade", "ano"));
     //Inicializando os objetos básicos
     $sqlUnidade = new SqlUnidade();
     $sqlSerie = new SqlSerie();
     $sqlEnsino = new SqlEnsino();
     $sqlAfa = new SqlAfa();
     //Contadores em geral
     $linha = 0;
     //Define a linha inicial da impressão da planilha
     $coluna = 0;
     //Define a coluna inicial da planilha
     $colunaInicial = $coluna;
     $r = 1;
     //Contador "R" das planilhas
     //Objetos e variaveis básicas da planilha
     $conceitos = array("D" => "Deficiente", "I" => "Insuficiente", "R" => "Regular", "B" => "Bom", "L" => "Louvor");
     $bimestres = array("1" => "1º Bimestre", "2" => "2º Bimestre", "3" => "3º Bimestre", "4" => "4º Bimestre");
     $bimRomanos = array("1" => "I", "2" => "II", "3" => "III", "4" => "IV");
     //Fazendo as consultas iniciais
     $ensinos = $sqlEnsino->listarTodos($this->filtro);
     $avaliacoea = $sqlAfa;
     $avaliacoes = $afaObj->listarAvaliacoes($unidade, $ano);
     die("ok");
     //Iniciando a geração da planilha
     while ($ensino = $ensinos->fetchObject()) {
         $avaliacoes = $afaObj->buscarAvaliacoes($ensino->pk_ensino, $unidade, $ano);
         //Teste para somente exibir as plainlhas de ensinos que contenham registros
         if (count($avaliacoes)) {
             //Ajustando a primeira coluna
             $this->workSheet->getColumnDimensionByColumn($coluna)->setWidth(33);
             //Trecho referente a primeira planilha
             //PREENCHENDO A PRIMEIRA PLANILHA
             //Definindo o título da planiplha
             $tituloPlanilhas = "TABELA R" . $r++ . " – DISTRIBUIÇÃO PERCENTUAL DOS CONCEITOS " . "FORMATIVOS DOS ALUNOS DO " . strtoupper($ensino->nome_ensino) . " EM CADA BIMESTRE";
             $this->workSheet->setCellValueByColumnAndRow($coluna, ++$linha, $tituloPlanilhas)->getStyleByColumnAndRow($coluna, $linha)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => "FFF2CC")), 'borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('argb' => '000000')))))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
             $this->workSheet->getStyleByColumnAndRow($coluna, $linha)->getFont()->setBold(TRUE);
             //Tornando a font bolder
             //
             $linhaReferencia = $linha;
             $linha++;
             $coluna++;
             //Criando o cabeçalho da primeira planilha
             foreach ($bimestres as $bimestre) {
                 $this->workSheet->setCellValueByColumnAndRow($coluna, $linha, $bimestre)->getStyleByColumnAndRow($coluna, $linha)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => "FCE4D6")), 'borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('argb' => '000000')))))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                 $this->workSheet->mergeCellsByColumnAndRow($coluna, $linha, $coluna + 4, $linha);
                 //Mesclando as colunas
                 $coluna += 5;
             }
             $this->workSheet->getStyleByColumnAndRow(--$coluna, $linha)->applyFromArray(array('borders' => array('right' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('argb' => '000000')))));
             $coluna = $colunaInicial;
             //Resetando o contador de colunas
             // Adicionando as colunas indicadoras de níveis
             $this->workSheet->setCellValueByColumnAndRow($coluna, $linha, "Série")->getStyleByColumnAndRow($coluna, $linha)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => "FCE4D6")), 'borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('argb' => '000000')))))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER)->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
             $this->workSheet->mergeCellsByColumnAndRow($coluna, $linha, $coluna++, ++$linha);
             //Mesclando as colunas
             //
             foreach (range(0, 3) as $indice) {
                 foreach (array_keys($conceitos) as $letra) {
                     $this->workSheet->setCellValueByColumnAndRow($coluna, $linha, $letra)->getStyleByColumnAndRow($coluna++, $linha)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => "FCE4D6")), 'borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('argb' => '000000')))))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                 }
             }
             //Mesclando o título da planilha
             $this->workSheet->mergeCellsByColumnAndRow($colunaInicial, $linhaReferencia, --$coluna, $linhaReferencia);
             $this->workSheet->getStyleByColumnAndRow($coluna, $linhaReferencia)->applyFromArray(array('borders' => array('right' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('argb' => '000000')))));
             //
             $linha++;
             //Definindo as variaveis para calculo de médias
             $mdD1B = $mdI1B = $mdR1B = $mdB1B = $mdL1B = array();
             $mdD2B = $mdI2B = $mdR2B = $mdB2B = $mdL2B = array();
             $mdD3B = $mdI3B = $mdR3B = $mdB3B = $mdL3B = array();
             $mdD4B = $mdI4B = $mdR4B = $mdB4B = $mdL4B = array();
             $this->workSheet->getStyleByColumnAndRow(--$coluna, $linha)->applyFromArray(array('borders' => array('right' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('argb' => '000000')))));
             $coluna = $colunaInicial;
             //Resetando o contador de colunas
             //adicionando as séries da primeira coluna
             foreach ($avaliacoes as $avaliacao) {
                 $this->workSheet->setCellValueByColumnAndRow($coluna, $linha, $avaliacao["serie_nome"])->getStyleByColumnAndRow($coluna++, $linha)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => "FCE4D6")), 'borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('argb' => '000000')))))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                 //Separando os dados
                 foreach (array_keys($bimestres) as $bimestre) {
                     foreach (array_keys($conceitos) as $conceito) {
                         $comando = '$qt' . $conceito . $bimestre . 'B = (float) ' . '(isset($avaliacao["qt-' . strtolower($conceito) . '-' . $bimestre . 'bi"]) ' . '? $avaliacao["qt-' . strtolower($conceito) . '-' . $bimestre . 'bi"] : 0.0);';
                         eval($comando);
                     }
                     $comando = '$qt' . $bimestre . 'B = (float) (isset($avaliacao["qt-' . $bimestre . 'bi"]) ' . '? $avaliacao["qt-' . $bimestre . 'bi"] : 0.0);';
                     eval($comando);
                 }
                 //Definindo os percentudais
                 foreach (array_keys($bimestres) as $bimestre) {
                     foreach (array_keys($conceitos) as $conceito) {
                         $comando = '$per' . $conceito . $bimestre . 'B = ' . 'Matematica::percentualDe($qt' . $conceito . $bimestre . 'B, $qt' . $bimestre . 'B);';
                         eval($comando);
                         $comando = 'array_push($md' . $conceito . $bimestre . 'B, $per' . $conceito . $bimestre . 'B);';
                         eval($comando);
                     }
                 }
                 //Adicionando os valores da coluna
                 foreach (array_keys($bimestres) as $bimestre) {
                     foreach (array_keys($conceitos) as $conceito) {
                         $comando = '$this->workSheet->setCellValueByColumnAndRow($coluna, ' . '$linha, $per' . $conceito . $bimestre . 'B)
                         ->getStyleByColumnAndRow($coluna++, $linha)
                         ->applyFromArray(//Aplicando formatação a celula
                                 array(
                                     "fill" => array(
                                         "type" => PHPExcel_Style_Fill::FILL_SOLID,
                                         "color" => array("rgb" => "FFF2CC")
                                     ),
                                     "borders" => array(
                                         "allborders" => array(
                                             "style" => PHPExcel_Style_Border::BORDER_THIN,
                                             "color" => array("argb" => "000000"),
                                         )
                                     )
                                 )
                         )
                         ->getAlignment()
                         ->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);';
                         eval($comando);
                     }
                 }
                 //
                 $coluna = $colunaInicial;
                 //Resetando o contador de colunas
                 $linha++;
                 //Incrementando a linha
             }
             //Definindo o texto da linha de médias
             $this->workSheet->setCellValueByColumnAndRow($coluna, $linha, "MÉDIA")->getStyleByColumnAndRow($coluna++, $linha)->applyFromArray(array("fill" => array("type" => PHPExcel_Style_Fill::FILL_SOLID, "color" => array("rgb" => "FCE4D6")), "borders" => array("allborders" => array("style" => PHPExcel_Style_Border::BORDER_THIN, "color" => array("argb" => "000000")))))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
             //Adicionando as médias
             foreach (array_keys($bimestres) as $bimestre) {
                 foreach (array_keys($conceitos) as $conceito) {
                     $comando = '$this->workSheet->setCellValueByColumnAndRow($coluna, ' . '$linha, Matematica::mediaAritimeticaArray($md' . $conceito . $bimestre . 'B))
                         ->getStyleByColumnAndRow($coluna++, $linha)
                         ->applyFromArray(//Aplicando formatação a celula
                                 array(
                                     "fill" => array(
                                         "type" => PHPExcel_Style_Fill::FILL_SOLID,
                                         "color" => array("rgb" => "FFF2CC")
                                     ),
                                     "borders" => array(
                                         "allborders" => array(
                                             "style" => PHPExcel_Style_Border::BORDER_THIN,
                                             "color" => array("argb" => "000000"),
                                         )
                                     )
                                 )
                         )
                         ->getAlignment()
                         ->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);';
                     eval($comando);
                 }
             }
             //Imcrementando a linha
             $linha++;
             $coluna = $colunaInicial;
             //Resetando o contador de colunas
             //-----------------------------------------------------------------------------------------------------
             //-----------------------------------------------------------------------------------------------------
             //-----------------------------------------------------------------------------------------------------
             //-----------------------------------------------------------------------------------------------------
             ////Trecho referente a primeira planilha
             //PREENCHENDO A PRIMEIRA PLANILHA
             //Definindo o título da planiplha
             $tituloPlanilhas = "TABELA R" . $r++ . " – DISTRIBUIÇÃO PERCENTUAL DOS CONCEITOS " . "FORMATIVOS DOS ALUNOS DO " . strtoupper($ensino->nome_ensino) . " AO LONGO DOS BIMESTRES";
             $this->workSheet->setCellValueByColumnAndRow($coluna, ++$linha, $tituloPlanilhas)->getStyleByColumnAndRow($coluna, $linha)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => "FFF2CC")), 'borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('argb' => '000000')))))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
             $this->workSheet->getStyleByColumnAndRow($coluna, $linha)->getFont()->setBold(TRUE);
             //Tornando a font bolder
             //
             $linhaReferencia = $linha;
             $linha++;
             $coluna++;
             //Criando o cabeçalho da primeira planilha
             foreach ($conceitos as $conceito) {
                 $this->workSheet->setCellValueByColumnAndRow($coluna, $linha, $conceito)->getStyleByColumnAndRow($coluna, $linha)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => "FCE4D6")), 'borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('argb' => '000000')))))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                 $this->workSheet->mergeCellsByColumnAndRow($coluna, $linha, $coluna + 3, $linha);
                 //Mesclando as colunas
                 $coluna += 4;
             }
             $this->workSheet->getStyleByColumnAndRow(--$coluna, $linha)->applyFromArray(array('borders' => array('right' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('argb' => '000000')))));
             //
             $coluna = $colunaInicial;
             //Resetando o contador de colunas
             // Adicionando as colunas indicadoras de níveis
             $this->workSheet->setCellValueByColumnAndRow($coluna, $linha, "Série")->getStyleByColumnAndRow($coluna, $linha)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => "FCE4D6")), 'borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('argb' => '000000')))))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER)->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
             $this->workSheet->mergeCellsByColumnAndRow($coluna, $linha, $coluna++, ++$linha);
             //Mesclando as colunas
             //
             foreach ($conceitos as $conceito) {
                 foreach (array_keys($bimestres) as $bimestre) {
                     $this->workSheet->setCellValueByColumnAndRow($coluna, $linha, $bimRomanos[$bimestre])->getStyleByColumnAndRow($coluna++, $linha)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => "FCE4D6")), 'borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('argb' => '000000')))))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                 }
             }
             //Mesclando o título da planilha
             $this->workSheet->mergeCellsByColumnAndRow($colunaInicial, $linhaReferencia, --$coluna, $linhaReferencia);
             $this->workSheet->getStyleByColumnAndRow($coluna, $linhaReferencia)->applyFromArray(array('borders' => array('right' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('argb' => '000000')))));
             //
             $linha++;
             //Definindo as variaveis para calculo de médias
             $mdD1B = $mdI1B = $mdR1B = $mdB1B = $mdL1B = array();
             $mdD2B = $mdI2B = $mdR2B = $mdB2B = $mdL2B = array();
             $mdD3B = $mdI3B = $mdR3B = $mdB3B = $mdL3B = array();
             $mdD4B = $mdI4B = $mdR4B = $mdB4B = $mdL4B = array();
             $coluna = $colunaInicial;
             //Resetando o contador de colunas
             //adicionando as séries da primeira coluna
             foreach ($avaliacoes as $avaliacao) {
                 $this->workSheet->setCellValueByColumnAndRow($coluna, $linha, $avaliacao["serie_nome"])->getStyleByColumnAndRow($coluna++, $linha)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => "FCE4D6")), 'borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('argb' => '000000')))))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                 //Separando os dados
                 foreach (array_keys($bimestres) as $bimestre) {
                     foreach (array_keys($conceitos) as $conceito) {
                         $comando = '$qt' . $conceito . $bimestre . 'B = (float) ' . '(isset($avaliacao["qt-' . strtolower($conceito) . '-' . $bimestre . 'bi"]) ' . '? $avaliacao["qt-' . strtolower($conceito) . '-' . $bimestre . 'bi"] : 0.0);';
                         eval($comando);
                     }
                     $comando = '$qt' . $bimestre . 'B = (float) (isset($avaliacao["qt-' . $bimestre . 'bi"]) ' . '? $avaliacao["qt-' . $bimestre . 'bi"] : 0.0);';
                     eval($comando);
                 }
                 //Definindo os percentudais
                 foreach (array_keys($bimestres) as $bimestre) {
                     foreach (array_keys($conceitos) as $conceito) {
                         $comando = '$per' . $conceito . $bimestre . 'B = ' . 'Matematica::percentualDe($qt' . $conceito . $bimestre . 'B, $qt' . $bimestre . 'B);';
                         eval($comando);
                         $comando = 'array_push($md' . $conceito . $bimestre . 'B, $per' . $conceito . $bimestre . 'B);';
                         eval($comando);
                     }
                 }
                 //Adicionando os valores da coluna
                 foreach (array_keys($conceitos) as $conceito) {
                     foreach (array_keys($bimestres) as $bimestre) {
                         $comando = '$this->workSheet->setCellValueByColumnAndRow($coluna, ' . '$linha, $per' . $conceito . $bimestre . 'B)
                         ->getStyleByColumnAndRow($coluna++, $linha)
                         ->applyFromArray(//Aplicando formatação a celula
                                 array(
                                     "fill" => array(
                                         "type" => PHPExcel_Style_Fill::FILL_SOLID,
                                         "color" => array("rgb" => "FFF2CC")
                                     ),
                                     "borders" => array(
                                         "allborders" => array(
                                             "style" => PHPExcel_Style_Border::BORDER_THIN,
                                             "color" => array("argb" => "000000"),
                                         )
                                     )
                                 )
                         )
                         ->getAlignment()
                         ->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);';
                         eval($comando);
                     }
                 }
                 //
                 $coluna = $colunaInicial;
                 //Resetando o contador de colunas
                 $linha++;
                 //Incrementando a linha
             }
             //Definindo o texto da linha de médias
             $this->workSheet->setCellValueByColumnAndRow($coluna, $linha, "MÉDIA")->getStyleByColumnAndRow($coluna++, $linha)->applyFromArray(array("fill" => array("type" => PHPExcel_Style_Fill::FILL_SOLID, "color" => array("rgb" => "FCE4D6")), "borders" => array("allborders" => array("style" => PHPExcel_Style_Border::BORDER_THIN, "color" => array("argb" => "000000")))))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
             //Adicionando as médias
             foreach (array_keys($conceitos) as $conceito) {
                 foreach (array_keys($bimestres) as $bimestre) {
                     $comando = '$this->workSheet->setCellValueByColumnAndRow($coluna, ' . '$linha, Matematica::mediaAritimeticaArray($md' . $conceito . $bimestre . 'B))
                         ->getStyleByColumnAndRow($coluna++, $linha)
                         ->applyFromArray(//Aplicando formatação a celula
                                 array(
                                     "fill" => array(
                                         "type" => PHPExcel_Style_Fill::FILL_SOLID,
                                         "color" => array("rgb" => "FFF2CC")
                                     ),
                                     "borders" => array(
                                         "allborders" => array(
                                             "style" => PHPExcel_Style_Border::BORDER_THIN,
                                             "color" => array("argb" => "000000"),
                                         )
                                     )
                                 )
                         )
                         ->getAlignment()
                         ->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);';
                     eval($comando);
                 }
             }
             //Imcrementando a linha
             $linha++;
             $coluna = $colunaInicial;
             //Resetando o contador de colunas
             //
         }
     }
     //Imprimindo a planuilha
     $this->printPlanilha("Avaliações");
 }