当前位置: 首页>>代码示例>>PHP>>正文


PHP PHPExcel_Worksheet::getDefaultStyle方法代码示例

本文整理汇总了PHP中PHPExcel_Worksheet::getDefaultStyle方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPExcel_Worksheet::getDefaultStyle方法的具体用法?PHP PHPExcel_Worksheet::getDefaultStyle怎么用?PHP PHPExcel_Worksheet::getDefaultStyle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PHPExcel_Worksheet的用法示例。


在下文中一共展示了PHPExcel_Worksheet::getDefaultStyle方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _initExcel

 /**
  * 
  */
 protected function _initExcel()
 {
     $this->_excel = new PHPExcel();
     $this->_excel->setActiveSheetIndex(0);
     $this->_mainSheet = $this->_excel->getActiveSheet();
     $styleArray = array('borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_NONE, 'color' => array('argb' => 'FFFFFFFF'))), 'fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('argb' => 'FFFFFFFF')), 'font' => array('name' => 'Calibri', 'size' => 10));
     $this->_mainSheet->getDefaultStyle()->applyFromArray($styleArray);
     $this->_mainSheet->getColumnDimension('A')->setVisible(false);
 }
开发者ID:fredcido,项目名称:simuweb,代码行数:12,代码来源:Excel.php

示例2: insertNewBefore

    /**
     * Insert a new column, updating all possible related data
     *
     * @param 	int	$pBefore	Insert before this one
     * @param 	int	$pNumCols	Number of columns to insert
     * @param 	int	$pNumRows	Number of rows to insert
     * @throws 	Exception
     */
    public function insertNewBefore($pBefore = 'A1', $pNumCols = 0, $pNumRows = 0, PHPExcel_Worksheet $pSheet = null) {
		// Get a copy of the cell collection
		/*$aTemp = $pSheet->getCellCollection();
		$aCellCollection = array();
		foreach ($aTemp as $key => $value) {
			$aCellCollection[$key] = clone $value;
		}*/
		$aCellCollection = $pSheet->getCellCollection();

    	// Get coordinates of $pBefore
    	$beforeColumn 	= 'A';
    	$beforeRow		= 1;
    	list($beforeColumn, $beforeRow) = PHPExcel_Cell::coordinateFromString( $pBefore );


		// Remove cell styles?
		$highestColumn 	= $pSheet->getHighestColumn();
		$highestRow 	= $pSheet->getHighestRow();

		if ($pNumCols < 0 && PHPExcel_Cell::columnIndexFromString($beforeColumn) - 2 + $pNumCols > 0) {
			for ($i = 1; $i <= $highestRow - 1; $i++) {

				$pSheet->duplicateStyle(
					new PHPExcel_Style(),
					(PHPExcel_Cell::stringFromColumnIndex( PHPExcel_Cell::columnIndexFromString($beforeColumn) - 1 + $pNumCols ) . $i) . ':' . (PHPExcel_Cell::stringFromColumnIndex( PHPExcel_Cell::columnIndexFromString($beforeColumn) - 2 ) . $i)
				);

			}
		}

		if ($pNumRows < 0 && $beforeRow - 1 + $pNumRows > 0) {
			for ($i = PHPExcel_Cell::columnIndexFromString($beforeColumn) - 1; $i <= PHPExcel_Cell::columnIndexFromString($highestColumn) - 1; $i++) {

				$pSheet->duplicateStyle(
					new PHPExcel_Style(),
					(PHPExcel_Cell::stringFromColumnIndex($i) . ($beforeRow + $pNumRows)) . ':' . (PHPExcel_Cell::stringFromColumnIndex($i) . ($beforeRow - 1))
				);

			}
		}


   		// Loop trough cells, bottom-up, and change cell coordinates
		while ( ($cell = ($pNumCols < 0 || $pNumRows < 0) ? array_shift($aCellCollection) : array_pop($aCellCollection)) ) {
			// New coordinates
			$newCoordinates = PHPExcel_Cell::stringFromColumnIndex( PHPExcel_Cell::columnIndexFromString($cell->getColumn()) - 1 + $pNumCols ) . ($cell->getRow() + $pNumRows);

			// Should the cell be updated?
			if (
					(PHPExcel_Cell::columnIndexFromString( $cell->getColumn() ) >= PHPExcel_Cell::columnIndexFromString($beforeColumn)) &&
				 	($cell->getRow() >= $beforeRow)
				 ) {

				// Update cell styles
				$pSheet->duplicateStyle( $pSheet->getStyle($cell->getCoordinate()), $newCoordinates . ':' . $newCoordinates );
				$pSheet->duplicateStyle( $pSheet->getDefaultStyle(), $cell->getCoordinate() . ':' . $cell->getCoordinate() );

				// Insert this cell at its new location
				if ($cell->getDataType() == PHPExcel_Cell_DataType::TYPE_FORMULA) {
					// Formula should be adjusted
					$pSheet->setCellValue(
						  $newCoordinates
						, $this->updateFormulaReferences($cell->getValue(), $pBefore, $pNumCols, $pNumRows)
					);
				} else {
					// Formula should not be adjusted
					$pSheet->setCellValue($newCoordinates, $cell->getValue());
				}

				// Clear the original cell
				$pSheet->setCellValue($cell->getCoordinate(), '');
			}
		}


		// Duplicate styles for the newly inserted cells
		$highestColumn 	= $pSheet->getHighestColumn();
		$highestRow 	= $pSheet->getHighestRow();

		if ($pNumCols > 0 && PHPExcel_Cell::columnIndexFromString($beforeColumn) - 2 > 0) {
			for ($i = $beforeRow; $i <= $highestRow - 1; $i++) {

				// Style
				$pSheet->duplicateStyle(
					$pSheet->getStyle(
						(PHPExcel_Cell::stringFromColumnIndex( PHPExcel_Cell::columnIndexFromString($beforeColumn) - 2 ) . $i)
					),
					($beforeColumn . $i) . ':' . (PHPExcel_Cell::stringFromColumnIndex( PHPExcel_Cell::columnIndexFromString($beforeColumn) - 2 + $pNumCols ) . $i)
				);

			}
		}
//.........这里部分代码省略.........
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:101,代码来源:ReferenceHelper.php

示例3: _writeCell

 /**
  * Write Cell
  *
  * @param	PHPExcel_Shared_XMLWriter	$objWriter				XML Writer
  * @param	PHPExcel_Worksheet			$pSheet					Worksheet
  * @param	PHPExcel_Cell				$pCell					Cell
  * @param	string[]					$pStringTable			String table
  * @param	string[]					$pFlippedStringTable	String table (flipped), for faster index searching
  * @throws	Exception
  */
 private function _writeCell(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null, PHPExcel_Cell $pCell = null, $pStringTable = null, $pFlippedStringTable = null)
 {
     if (is_array($pStringTable) && is_array($pFlippedStringTable)) {
         // Cell
         $objWriter->startElement('c');
         $objWriter->writeAttribute('r', $pCell->getCoordinate());
         // Sheet styles
         $aStyles = $pSheet->getStyles();
         $styleIndex = '';
         if (isset($aStyles[$pCell->getCoordinate()])) {
             $styleIndex = $aStyles[$pCell->getCoordinate()]->getHashIndex();
         } else {
             $styleIndex = $pSheet->getDefaultStyle()->getHashIndex();
         }
         if ($styleIndex != '') {
             $objWriter->writeAttribute('s', $styleIndex);
         }
         // If cell value is supplied, write cell value
         if (is_object($pCell->getValue()) || $pCell->getValue() !== '') {
             // Map type
             $mappedType = $pCell->getDataType();
             // Write data type depending on its type
             switch (strtolower($mappedType)) {
                 case 'inlinestr':
                     // Inline string
                     $objWriter->writeAttribute('t', $mappedType);
                     break;
                 case 's':
                     // String
                     $objWriter->writeAttribute('t', $mappedType);
                     break;
                 case 'b':
                     // Boolean
                     $objWriter->writeAttribute('t', $mappedType);
                     break;
                 case 'f':
                     // Formula
                     $calculatedValue = null;
                     if ($this->getParentWriter()->getPreCalculateFormulas()) {
                         $calculatedValue = $pCell->getCalculatedValue();
                     } else {
                         $calculatedValue = $pCell->getValue();
                     }
                     if (is_string($calculatedValue)) {
                         $objWriter->writeAttribute('t', 'str');
                     }
                     break;
                 case 'e':
                     // Error
                     $objWriter->writeAttribute('t', $mappedType);
             }
             // Write data depending on its type
             switch (strtolower($mappedType)) {
                 case 'inlinestr':
                     // Inline string
                     if (!$pCell->getValue() instanceof PHPExcel_RichText) {
                         $objWriter->writeElement('t', PHPExcel_Shared_String::ControlCharacterPHP2OOXML(htmlspecialchars($pCell->getValue())));
                     } else {
                         if ($pCell->getValue() instanceof PHPExcel_RichText) {
                             $objWriter->startElement('is');
                             $this->getParentWriter()->getWriterPart('stringtable')->writeRichText($objWriter, $pCell->getValue());
                             $objWriter->endElement();
                         }
                     }
                     break;
                 case 's':
                     // String
                     if (!$pCell->getValue() instanceof PHPExcel_RichText) {
                         if (isset($pFlippedStringTable[$pCell->getValue()])) {
                             $objWriter->writeElement('v', $pFlippedStringTable[$pCell->getValue()]);
                         }
                     } else {
                         if ($pCell->getValue() instanceof PHPExcel_RichText) {
                             $objWriter->writeElement('v', $pFlippedStringTable[$pCell->getValue()->getHashCode()]);
                         }
                     }
                     break;
                 case 'f':
                     // Formula
                     $objWriter->writeElement('f', substr($pCell->getValue(), 1));
                     if ($this->getParentWriter()->getOffice2003Compatibility() === false) {
                         if ($this->getParentWriter()->getPreCalculateFormulas()) {
                             $calculatedValue = $pCell->getCalculatedValue();
                             if (!is_array($calculatedValue) && substr($calculatedValue, 0, 1) != '#') {
                                 $objWriter->writeElement('v', $calculatedValue);
                             } else {
                                 $objWriter->writeElement('v', '0');
                             }
                         } else {
                             $objWriter->writeElement('v', '0');
//.........这里部分代码省略.........
开发者ID:nagiro,项目名称:hospici_cultural,代码行数:101,代码来源:Worksheet.php

示例4: load


//.........这里部分代码省略.........
         foreach ($this->_builtInStyles as &$builtInStyle) {
             // fonts
             $builtInStyle['font']['color'] = $this->_readColor($builtInStyle['font']['colorIndex']);
             // fill start and end color
             $builtInStyle['fill']['startcolor'] = $this->_readColor($builtInStyle['fill']['startcolorIndex']);
             $builtInStyle['fill']['endcolor'] = $this->_readColor($builtInStyle['fill']['endcolorIndex']);
             // border colors
             $builtInStyle['borders']['top']['color'] = $this->_readColor($builtInStyle['borders']['top']['colorIndex']);
             $builtInStyle['borders']['right']['color'] = $this->_readColor($builtInStyle['borders']['right']['colorIndex']);
             $builtInStyle['borders']['bottom']['color'] = $this->_readColor($builtInStyle['borders']['bottom']['colorIndex']);
             $builtInStyle['borders']['left']['color'] = $this->_readColor($builtInStyle['borders']['left']['colorIndex']);
         }
     }
     // treat MSODRAWINGGROUP records, workbook-level Escher
     if (!$this->_readDataOnly && $this->_drawingGroupData) {
         $escherWorkbook = new PHPExcel_Shared_Escher();
         $reader = new PHPExcel_Reader_Excel5_Escher($escherWorkbook);
         $escherWorkbook = $reader->load($this->_drawingGroupData);
         // debug Escher stream
         //$debug = new Debug_Escher(new PHPExcel_Shared_Escher());
         //$debug->load($this->_drawingGroupData);
     }
     // Parse the individual sheets
     foreach ($this->_sheets as $sheet) {
         // check if sheet should be skipped
         if (isset($this->_loadSheetsOnly) && !in_array($sheet['name'], $this->_loadSheetsOnly)) {
             continue;
         }
         // add sheet to PHPExcel object
         $this->_phpSheet = $this->_phpExcel->createSheet();
         $this->_phpSheet->setTitle($sheet['name']);
         // default style
         if (!$this->_readDataOnly && isset($this->_builtInStyles[0])) {
             $this->_phpSheet->getDefaultStyle()->applyFromArray($this->_builtInStyles[0]);
         }
         $this->_pos = $sheet['offset'];
         // Initialize isFitToPages. May change after reading SHEETPR record.
         $this->_isFitToPages = false;
         // Initialize drawingData
         $this->_drawingData = '';
         // Initialize objs
         $this->_objs = array();
         while ($this->_pos < $this->_dataSize) {
             $code = $this->_GetInt2d($this->_data, $this->_pos);
             switch ($code) {
                 case self::XLS_Type_BOF:
                     $length = $this->_GetInt2d($this->_data, $this->_pos + 2);
                     $recordData = substr($this->_data, $this->_pos + 4, $length);
                     // move stream pointer to next record
                     $this->_pos += 4 + $length;
                     // do not use this version information for anything
                     // it is unreliable (OpenOffice doc, 5.8), use only version information from the global stream
                     // offset: 2; size: 2; type of the following data
                     $substreamType = $this->_GetInt2d($recordData, 2);
                     if ($substreamType != self::XLS_Worksheet) {
                         break 2;
                     }
                     break;
                 case self::XLS_Type_PRINTGRIDLINES:
                     $this->_readPrintGridlines();
                     break;
                 case self::XLS_Type_DEFAULTROWHEIGHT:
                     $this->_readDefaultRowHeight();
                     break;
                 case self::XLS_Type_SHEETPR:
                     $this->_readSheetPr();
开发者ID:kaantunc,项目名称:MYK-BOR,代码行数:67,代码来源:Excel5.php

示例5: close

 /**
  * Add data to the beginning of the workbook (note the reverse order)
  * and to the end of the workbook.
  *
  * @access public
  * @see PHPExcel_Writer_Excel5_Workbook::storeWorkbook()
  */
 function close()
 {
     $num_sheets = count($this->_phpSheet->getParent()->getAllSheets());
     // Write BOF record
     $this->_storeBof(0x10);
     // Write DEFCOLWIDTH record
     $this->_storeDefcol();
     // Calculate column widths
     $this->_phpSheet->calculateColumnWidths();
     // Column dimensions
     foreach ($this->_phpSheet->getColumnDimensions() as $columnDimension) {
         $column = PHPExcel_Cell::columnIndexFromString($columnDimension->getColumnIndex()) - 1;
         if ($column < 256) {
             if ($columnDimension->getWidth() >= 0) {
                 $width = $columnDimension->getWidth();
             } else {
                 if ($this->_phpSheet->getDefaultColumnDimension()->getWidth() >= 0) {
                     $width = $this->_phpSheet->getDefaultColumnDimension()->getWidth();
                 } else {
                     $width = 8;
                 }
             }
             $this->_setColumn($column, $column, $width, null, $columnDimension->getVisible() ? '0' : '1', $columnDimension->getOutlineLevel());
         }
     }
     // Write the COLINFO records if they exist
     if (!empty($this->_colinfo)) {
         $colcount = count($this->_colinfo);
         for ($i = 0; $i < $colcount; ++$i) {
             $this->_storeColinfo($this->_colinfo[$i]);
         }
     }
     // Write EXTERNCOUNT of external references
     if ($this->_BIFF_version == 0x500) {
         $this->_storeExterncount($num_sheets);
     }
     // Write EXTERNSHEET references
     if ($this->_BIFF_version == 0x500) {
         for ($i = 0; $i < $num_sheets; ++$i) {
             $this->_storeExternsheet($this->_phpSheet->getParent()->getSheet($i)->getTitle());
         }
     }
     // Write PRINTHEADERS
     $this->_storePrintHeaders();
     // Write PRINTGRIDLINES
     $this->_storePrintGridlines();
     // Write GUTS
     $this->_storeGuts();
     // Write GRIDSET
     $this->_storeGridset();
     // Write DEFAULTROWHEIGHT
     if ($this->_BIFF_version == 0x600) {
         $this->_storeDefaultRowHeight();
     }
     // Write WSBOOL
     $this->_storeWsbool();
     // Write horizontal and vertical page breaks
     $this->_storeBreaks();
     // Write page header
     $this->_storeHeader();
     // Write page footer
     $this->_storeFooter();
     // Write page horizontal centering
     $this->_storeHcenter();
     // Write page vertical centering
     $this->_storeVcenter();
     // Write left margin
     $this->_storeMarginLeft();
     // Write right margin
     $this->_storeMarginRight();
     // Write top margin
     $this->_storeMarginTop();
     /* FIXME: margins are actually appended */
     // Write bottom margin
     $this->_storeMarginBottom();
     // Write page setup
     $this->_storeSetup();
     // Write sheet protection
     $this->_storeProtect();
     // Write sheet password
     $this->_storePassword();
     // Write sheet dimensions
     $this->_storeDimensions();
     // Write Cells
     $aStyles = $this->_phpSheet->getStyles();
     $emptyStyle = $this->_phpSheet->getDefaultStyle();
     foreach ($this->_phpSheet->getCellCollection() as $cell) {
         $row = $cell->getRow() - 1;
         $column = PHPExcel_Cell::columnIndexFromString($cell->getColumn()) - 1;
         // Don't break Excel!
         if ($row + 1 > 65536 or $column + 1 > 256) {
             break;
         }
//.........这里部分代码省略.........
开发者ID:roelvanduijnhoven,项目名称:muzieklijstjes,代码行数:101,代码来源:Worksheet.php


注:本文中的PHPExcel_Worksheet::getDefaultStyle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。