Advertisement
Guest User

webix php exportToExcel lib

a guest
Jul 16th, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.56 KB | None | 0 0
  1. ####gridExcelGenerator.php
  2.  
  3.     private function rowsParse($rows) {
  4.         $i = 0;
  5.         foreach ($rows as $row) {
  6.             $rowArr = Array();
  7.             $cellColors = Array();
  8.             $cells = $row->cell;
  9.             $k = 0;
  10.             foreach ($cells as $cell) {
  11.                 if (isset($this->hiddenCols[$k])) {
  12.                     $k++;
  13.                     continue;
  14.                 }
  15.                 $cell_p = Array();
  16.                 if (isset($this->coll_options[$k][trim((string) $cell)]))
  17.                     $cell_p['text'] = $this->strip($this->coll_options[$k][trim((string) $cell)]);
  18.                 else
  19.                     $cell_p['text'] = $this->strip(trim((string) $cell));
  20.  
  21.                 if (isset($cell->attributes()->bgColor)) {
  22.                     $cell_p['bg'] = (string) $cell->attributes()->bgColor;
  23.                 } else {
  24.                     $color = ($i%2 == 0) ? $this->scaleOneColor : $this->scaleTwoColor;
  25.                     $cell_p['bg'] = $color;
  26.                 }
  27.                 if (isset($cell->attributes()->textColor)) {
  28.                     $cell_p['textColor'] = (string) $cell->attributes()->textColor;
  29.                 } else {
  30.                     $cell_p['textColor'] = $this->textColor;
  31.                 }
  32.                 ### mod ###
  33.                 if (isset($row->attributes()->level)){
  34.                     $cell_p['indent'] = $row->attributes()->level;
  35.                 }
  36.                 ### end mod ###
  37.                 $cell_p['bold'] = (isset($cell->attributes()->bold) && $cell->attributes()->bold == 'bold') ? true : false;
  38.                 $cell_p['italic'] = (isset($cell->attributes()->italic) && $cell->attributes()->italic == 'italic') ? true : false;
  39.                 $cell_p['align'] = isset($cell->attributes()->align) ? $cell->attributes()->align : false;
  40.                 $rowArr[] = $cell_p;
  41.                 $k++;
  42.             }
  43.             $this->rows[] = $rowArr;
  44.             $i++;
  45.         }
  46.     }
  47.  
  48. ####gridExcelWrapper.php
  49. public function rowPrint($row, $rowHeight, $lineColor, $gridFontSize, $fontFamily) {
  50.         $this->excel->getActiveSheet()->getRowDimension($this->currentRow)->setRowHeight($rowHeight);
  51.         $styleArray = array(
  52.             'borders' => array(
  53.                 'allborders' => array(
  54.                     'style' => PHPExcel_Style_Border::BORDER_THIN,
  55.                     'color' => array('argb' => $this->processColor($lineColor)),
  56.                 ),
  57.             ),
  58.             'fill' => array(
  59.                 'type' => PHPExcel_Style_Fill::FILL_SOLID,
  60.                 'rotation' => 90
  61.             ),
  62.             'font' => array(
  63.                 'bold' => false,
  64.                 'name' => $fontFamily,
  65.                 'size' => $gridFontSize,
  66.                 'color'=> Array('rgb'=> $this->processColor($this->textColor))
  67.             )
  68.         );
  69.         $this->excel->getActiveSheet()->getStyle(($this->getColName(0).$this->currentRow.':'.$this->getColName(count($row) - 1).$this->currentRow))->applyFromArray($styleArray);
  70.  
  71.         for ($i = 0; $i < count($row); $i++) {
  72.             if ($i >= count($this->types)) continue;
  73.  
  74.             $this->excel->getActiveSheet()->getStyle(($this->getColName($i).$this->currentRow.':'.$this->getColName($i).$this->currentRow))->applyFromArray($styleArray);
  75.  
  76.             $styleArray['font']['bold'] = $row[$i]['bold'];
  77.             $styleArray['font']['italic'] = $row[$i]['italic'];
  78.  
  79.             $this->excel->setActiveSheetIndex(0);
  80.             $text = $row[$i]['text'];
  81.             if ((isset($this->columns[0][$i]['type']))&&(($this->columns[0][$i]['type'] == 'ch')||($this->columns[0][$i]['type'] == 'ra'))) {
  82.                 if ($text == '1') {
  83.                     $text = 'Yes';
  84.                 } else {
  85.                     $text = 'No';
  86.                 }
  87.             }
  88.  
  89.             switch (strtolower($this->types[$i])) {
  90.                 case 'string':
  91.                 case 'str':
  92.                 case 'txt':
  93.                 case 'edtxt':
  94.                 case 'rotxt':
  95.                 case 'ro':
  96.                 case 'co':
  97.                 case 'coro':
  98.                     $this->excel->getActiveSheet()->getCell($this->getColName($i).$this->currentRow)->setValueExplicit($text, PHPExcel_Cell_DataType::TYPE_STRING);
  99.                     break;
  100.                 case 'number':
  101.                 case 'num':
  102.                 case 'edn':
  103.                 case 'ron':
  104.                     $text = str_replace(",", ".", $text);
  105.                     $this->excel->getActiveSheet()->getCell($this->getColName($i).$this->currentRow)->setValueExplicit($text, PHPExcel_Cell_DataType::TYPE_NUMERIC);
  106.                     break;
  107.                 case 'boolean':
  108.                 case 'bool':
  109.                     $this->excel->getActiveSheet()->getCell($this->getColName($i).$this->currentRow)->setValueExplicit($text, PHPExcel_Cell_DataType::TYPE_BOOL);
  110.                     break;
  111.                 case 'formula':
  112.                     $this->excel->getActiveSheet()->getCell($this->getColName($i).$this->currentRow)->setValueExplicit($text, PHPExcel_Cell_DataType::TYPE_FORMULA);
  113.                     break;
  114.                 case 'date':
  115.                     $this->excel->getActiveSheet()->setCellValueByColumnAndRow($i, $this->currentRow, $text);
  116.                     $this->excel->getActiveSheet()->getStyle($this->getColName($i).$this->currentRow)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2);
  117.                     break;
  118.                 ### mod ###
  119.                 case 'tree':
  120.                     $this->excel->getActiveSheet()->setCellValueByColumnAndRow($i, $this->currentRow, $text);
  121.                     $this->excel->getActiveSheet()->getStyle($this->getColName($i).$this->currentRow)->getAlignment()->setIndent($row[$i]['indent']);
  122.                     break;
  123.                 ### end mod ###
  124.                 default:
  125.                     $this->excel->getActiveSheet()->setCellValueByColumnAndRow($i, $this->currentRow, $text);
  126.                     break;
  127.             }
  128.             $this->excel->getActiveSheet()->getStyle($this->getColName($i).$this->currentRow)->getFill()->getStartColor()->setRGB($this->getRGB($row[$i]['bg']));
  129.             $this->excel->getActiveSheet()->getStyle($this->getColName($i).$this->currentRow)->getFont()->getColor()->setRGB($this->getRGB($row[$i]['textColor']));
  130.             $this->excel->getActiveSheet()->getStyle($this->getColName($i).$this->currentRow)->getFont()->getColor()->setRGB($this->getRGB($row[$i]['textColor']));
  131.             $align = $row[$i]['align'];
  132.             if ($align == false) $align = $this->columns[0][$i]['align'];
  133.             $this->excel->getActiveSheet()->getStyle($this->getColName($i).$this->currentRow)->getAlignment()->setHorizontal($align);
  134.             $this->excel->getActiveSheet()->getStyle($this->getColName($i).$this->currentRow)->getAlignment()->setWrapText(true);
  135.         }
  136.  
  137.         $this->currentRow++;
  138.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement