Beispiel #1
0
 /**
  * Property Begin Bind
  *
  * If no PHPExcel_Style_Font has been bound to PHPExcel_Style then bind this one. Return the actual bound one.
  *
  * @return PHPExcel_Style_Font
  */
 private function propertyBeginBind()
 {
     if (!isset($this->_parent)) {
         return $this;
     }
     // I am already bound
     if ($this->_parent->propertyIsBound($this->_parentPropertyName)) {
         return $this->_parent->getFont();
     }
     // Another one is already bound
     $this->_parent->propertyCompleteBind($this, $this->_parentPropertyName);
     // Bind myself
     $this->_parent = null;
     return $this;
 }
 /**
  * Set default style - should only be used by PHPExcel_IReader implementations!
  *
  * @deprecated
  * @param PHPExcel_Style $pValue
  * @throws PHPExcel_Exception
  * @return PHPExcel_Worksheet
  */
 public function setDefaultStyle(PHPExcel_Style $pValue)
 {
     $this->_parent->getDefaultStyle()->applyFromArray(array('font' => array('name' => $pValue->getFont()->getName(), 'size' => $pValue->getFont()->getSize())));
     return $this;
 }
Beispiel #3
0
 /**
  * Create CSS style
  *
  * @param	PHPExcel_Style		$pStyle			PHPExcel_Style
  * @return	array
  */
 private function _createCSSStyle(PHPExcel_Style $pStyle)
 {
     // Construct CSS
     $css = '';
     // Create CSS
     $css = array_merge($this->_createCSSStyleAlignment($pStyle->getAlignment()), $this->_createCSSStyleBorders($pStyle->getBorders()), $this->_createCSSStyleFont($pStyle->getFont()), $this->_createCSSStyleFill($pStyle->getFill()));
     // Return
     return $css;
 }
Beispiel #4
0
 /**
  * Write Cell Style Dxf
  *
  * @param 	PHPExcel_Shared_XMLWriter 		$objWriter 		XML Writer
  * @param 	PHPExcel_Style					$pStyle			Style
  * @throws 	Exception
  */
 private function _writeCellStyleDxf(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style $pStyle = null)
 {
     // dxf
     $objWriter->startElement('dxf');
     // font
     $this->_writeFont($objWriter, $pStyle->getFont());
     // numFmt
     $this->_writeNumFmt($objWriter, $pStyle->getNumberFormat());
     // fill
     $this->_writeFill($objWriter, $pStyle->getFill());
     // alignment
     $objWriter->startElement('alignment');
     $objWriter->writeAttribute('horizontal', $pStyle->getAlignment()->getHorizontal());
     $objWriter->writeAttribute('vertical', $pStyle->getAlignment()->getVertical());
     $textRotation = 0;
     if ($pStyle->getAlignment()->getTextRotation() >= 0) {
         $textRotation = $pStyle->getAlignment()->getTextRotation();
     } else {
         if ($pStyle->getAlignment()->getTextRotation() < 0) {
             $textRotation = 90 - $pStyle->getAlignment()->getTextRotation();
         }
     }
     $objWriter->writeAttribute('textRotation', $textRotation);
     $objWriter->endElement();
     // border
     $this->_writeBorder($objWriter, $pStyle->getBorders());
     // protection
     if ($pStyle->getProtection()->getLocked() != PHPExcel_Style_Protection::PROTECTION_INHERIT || $pStyle->getProtection()->getHidden() != PHPExcel_Style_Protection::PROTECTION_INHERIT) {
         $objWriter->startElement('protection');
         if ($pStyle->getProtection()->getLocked() != PHPExcel_Style_Protection::PROTECTION_INHERIT) {
             $objWriter->writeAttribute('locked', $pStyle->getProtection()->getLocked() == PHPExcel_Style_Protection::PROTECTION_PROTECTED ? 'true' : 'false');
         }
         if ($pStyle->getProtection()->getHidden() != PHPExcel_Style_Protection::PROTECTION_INHERIT) {
             $objWriter->writeAttribute('hidden', $pStyle->getProtection()->getHidden() == PHPExcel_Style_Protection::PROTECTION_PROTECTED ? 'true' : 'false');
         }
         $objWriter->endElement();
     }
     $objWriter->endElement();
 }
error_reporting(E_ALL);
ini_set('display_errors', true);
ini_set('display_startup_errors', true);
date_default_timezone_set('Europe/London');
define('EOL', PHP_SAPI == 'cli' ? PHP_EOL : '<br />');
date_default_timezone_set('Europe/London');
/** Include PHPExcel */
require_once dirname(__FILE__) . '/../Classes/PHPExcel.php';
echo date('H:i:s'), " Create new PHPExcel object", EOL;
$objPHPExcel = new PHPExcel();
$worksheet = $objPHPExcel->getActiveSheet();
echo date('H:i:s'), " Create styles array", EOL;
$styles = array();
for ($i = 0; $i < 10; $i++) {
    $style = new PHPExcel_Style();
    $style->getFont()->setSize($i + 4);
    $styles[] = $style;
}
echo date('H:i:s'), " Add data (begin)", EOL;
$t = microtime(true);
for ($col = 0; $col < 50; $col++) {
    for ($row = 0; $row < 100; $row++) {
        $str = $row + $col;
        $style = $styles[$row % 10];
        $coord = PHPExcel_Cell::stringFromColumnIndex($col) . ($row + 1);
        $worksheet->setCellValue($coord, $str);
        $worksheet->duplicateStyle($style, $coord);
    }
}
$d = microtime(true) - $t;
echo date('H:i:s'), " Add data (end), time: " . round($d, 2) . " s", EOL;
Beispiel #6
0
 /**
  * Create CSS style
  * 
  * @param	PHPExcel_Style 		$pStyle			PHPExcel_Style
  * @return	string
  */
 private function _createCSSStyle(PHPExcel_Style $pStyle)
 {
     // Construct HTML
     $html = '';
     // Create CSS
     $html .= '      .style' . $pStyle->getHashCode() . ' {' . "\r\n";
     $html .= $this->_createCSSStyleAlignment($pStyle->getAlignment());
     $html .= $this->_createCSSStyleFont($pStyle->getFont());
     $html .= $this->_createCSSStyleBorders($pStyle->getBorders());
     $html .= $this->_createCSSStyleFill($pStyle->getFill());
     $html .= '      }' . "\r\n";
     // Return
     return $html;
 }
		/**
		 * Generates the sheet's workbook...
		 *
		 * @param String format extension
		 */
		function _generateSheets($format){


			$sheets= array();
			$sheets= $this->book->getSheets();
			$i= 0;


			if ($format=="ods"){

				foreach($sheets as $sheet){

					$cells= array();
					$cells= $sheet->getCells();


					foreach($cells as $cellarray){

						foreach($cellarray as $cell){

						$col= $cell->getDataColumn();
						$row= $cell->getDataRow();
						$data= $cell->getFormula();
						$fontId= $cell->getFontStyleId();
						$fontStyle= new FontStyle();
						$fontStyle= $this->book->getFontStyle($fontId);
						
						

						if (substr($data, 0, 1)== '=')

							$this->objPHPOds->addCell($i,$row,$col,substr($data, 1),'float');
							

						//TODO
						else /*OJO CON ESTO DISCERNIR ENTRE LOS DIFERENTES TIPOS*/

							$this->objPHPOds->addCell($i,$row,$col,$data,'string');

						}
						$this->objPHPOds->addStyle($fontStyle, $cell);
					}
					$i++;
				}
			}
			else{

				foreach($sheets as $sheet){

					if ($i>0)
						$this->objPHPExcel->createSheet();

					$this->objPHPExcel->setActiveSheetIndex($i);
					$j= $i + 1;
					$this->objPHPExcel->getActiveSheet()->setTitle("Sheet $j");

					$cells= array();
					
					$cells= $sheet->getCells();

					foreach($cells as $cellarray){

						$cell= new Cell();
						foreach ($cellarray as $cell){

						
							$col= $cell->getDataColumn();
							$row= $cell->getDataRow();
							$row++;
							
							$data= $cell->getFormula();
//							$this->objPHPExcel= new PHPExcel();
							
							
							$fontId= $cell->getFontStyleId();
							$fontStyle= new FontStyle();
							$fontStyle= $this->book->getFontStyle($fontId);
							$fontName= $fontStyle->getFontName();	
							$fcolor= substr($fontStyle->getFontColor(),1);
							
							if ($fcolor == "000000"){ 
								//echo "$row $col $fcolor<hr>";
							 	$ncolor= new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_BLACK);
							 	$ncolor->setRGB($fcolor);							 	
							}
							else{
								//echo "$row $col $fcolor<hr>";
								$ncolor= new PHPExcel_Style_Color();
								$ncolor->setRGB($fcolor);				
							}	
							
							$style= new PHPExcel_Style();
							$style->getFont()->setColor($ncolor);
							$style->getFont()->setName($fontName);
							$style->getFont()->setBold($fontStyle->getFontBold()== 1);
							$style->getFont()->setItalic($fontStyle->getFontItalic()==1);
							$style->getFont()->setSize($fontStyle->getFontSize());
							
							
							$HzAlign= PHPExcel_Style_Alignment::HORIZONTAL_GENERAL;
							
							switch ($fontStyle->fontHAlign){
								
								case 0:									
									$HzAlign= PHPExcel_Style_Alignment::HORIZONTAL_GENERAL;
									break;
								case 1:									
									$HzAlign= PHPExcel_Style_Alignment::HORIZONTAL_LEFT;
									break;
								case 2:									
									$HzAlign= PHPExcel_Style_Alignment::HORIZONTAL_CENTER;
									break;
								case 3:									
									$HzAlign= PHPExcel_Style_Alignment::HORIZONTAL_RIGHT;
									break;								
							}
				
							$VlAlign= PHPExcel_Style_Alignment::VERTICAL_BOTTOM;
							
							switch ($fontStyle->fontVAlign){
								
								case 0:									
									$VlAlign= PHPExcel_Style_Alignment::VERTICAL_BOTTOM;
									break;
								case 1:									
									$VlAlign= PHPExcel_Style_Alignment::VERTICAL_CENTER;
									break;
								case 2:									
									$VlAlign= PHPExcel_Style_Alignment::VERTICAL_TOP;							
															
							}						
							
							$style->getAlignment()->setHorizontal($HzAlign);
							$style->getAlignment()->setVertical($VlAlign);
							
							
							if ($fontStyle->getFontUnderline()!= 0){
								$style->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE);
							}
														
							$this->objPHPExcel->getActiveSheet()->duplicateStyle($style, PHPExcel_Cell::stringFromColumnIndex($col) . $row);
							$this->objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col, $row)->setValueExplicit($data, PHPExcel_Cell_DataType::dataTypeForValue($data));							
											
						}
						
					}
						$i++;

					}

				}

		}