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


PHP PHPExcel::getSheetByName方法代码示例

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


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

示例1: load


//.........这里部分代码省略.........

												$docSheet->getPageSetup()->setPrintArea($extractedRange);
												break;

											default:
												break;
										}
									}
								}
							}

							// Next sheet id
							++$sheetId;
						}

						// Loop through definedNames
						if ($xmlWorkbook->definedNames) {
							foreach ($xmlWorkbook->definedNames->definedName as $definedName) {
								// Extract range
								$extractedRange = (string)$definedName;
								$extractedRange = preg_replace('/\'(\w+)\'\!/', '', $extractedRange);
								$extractedRange = str_replace('$', '', $extractedRange);

								// Valid range?
								if (stripos((string)$definedName, '#REF!') !== false || $extractedRange == '') {
									continue;
								}

								// Some definedNames are only applicable if we are on the same sheet...
								if ((string)$definedName['localSheetId'] != '') {
									// Local defined name
									// Switch on type
									switch ((string)$definedName['name']) {

										case '_xlnm._FilterDatabase':
										case '_xlnm.Print_Titles':
										case '_xlnm.Print_Area':
											break;

										default:
											$range = explode('!', (string)$definedName);
											if (count($range) == 2) {
												$range[0] = str_replace("''", "'", $range[0]);
												$range[0] = str_replace("'", "", $range[0]);
												if ($worksheet = $docSheet->getParent()->getSheetByName($range[0])) {
													$extractedRange = str_replace('$', '', $range[1]);
													$scope = $docSheet->getParent()->getSheet((string)$definedName['localSheetId']);

													$excel->addNamedRange( new PHPExcel_NamedRange((string)$definedName['name'], $worksheet, $extractedRange, true, $scope) );
												}
											}
											break;
									}
								} else if (!isset($definedName['localSheetId'])) {
									// "Global" definedNames
									$locatedSheet = null;
									$extractedSheetName = '';
									if (strpos( (string)$definedName, '!' ) !== false) {
										// Extract sheet name
										$extractedSheetName = PHPExcel_Worksheet::extractSheetTitle( (string)$definedName, true );
										$extractedSheetName = $extractedSheetName[0];

										// Locate sheet
										$locatedSheet = $excel->getSheetByName($extractedSheetName);

										// Modify range
										$range = explode('!', $extractedRange);
										$extractedRange = isset($range[1]) ? $range[1] : $range[0];
									}

									if (!is_null($locatedSheet)) {
										$excel->addNamedRange( new PHPExcel_NamedRange((string)$definedName['name'], $locatedSheet, $extractedRange, false) );
									}
								}
							}
						}
					}

					if (!$this->_readDataOnly) {
						// active sheet index
						$activeTab = intval($xmlWorkbook->bookViews->workbookView["activeTab"]); // refers to old sheet index

						// keep active sheet index if sheet is still loaded, else first sheet is set as the active
						if (isset($mapSheetId[$activeTab]) && $mapSheetId[$activeTab] !== null) {
							$excel->setActiveSheetIndex($mapSheetId[$activeTab]);
						} else {
							if ($excel->getSheetCount() == 0)
							{
								$excel->createSheet();
							}
							$excel->setActiveSheetIndex(0);
						}
					}
				break;
			}

		}

		return $excel;
	}
开发者ID:Opmantek,项目名称:open-audit,代码行数:101,代码来源:Excel2007.php

示例2: getSheetByIdOrName

 /**
  * Get the sheet by id or name, else get the active sheet
  *
  * @param callable|integer|string $sheetID
  *
  * @return \PHPExcel_Worksheet
  */
 protected function getSheetByIdOrName($sheetID)
 {
     // If is a string, return the sheet by name
     if (is_string($sheetID)) {
         return $this->excel->getSheetByName($sheetID);
     }
     // Else it should be the sheet index
     return $this->excel->getSheet($sheetID);
 }
开发者ID:thesaputra,项目名称:xyz-prx,代码行数:16,代码来源:LaravelExcelReader.php

示例3: __construct

 public function __construct(\PHPExcel $template, LoggerInterface $logger = null)
 {
     $this->logger = $logger ? $logger : new NullLogger();
     $templateSheet = $template->getSheetByName('TEMPLATE');
     if (!$templateSheet) {
         throw new \InvalidArgumentException("A sheet named 'TEMPLATE' must exist.");
     }
     $this->prepare($templateSheet);
 }
开发者ID:mathielen,项目名称:report-write-engine,代码行数:9,代码来源:ExcelCanvasWriter.php

示例4: getWorksheet

 /**
  * Returns the worksheet for a set of data
  *
  * @param array $data
  *
  * @return \PHPExcel_Worksheet
  */
 protected function getWorksheet(array $data)
 {
     $name = $this->getWorksheetName($data);
     if (!isset($this->labels[$name])) {
         return $this->createWorksheet($name, $data);
     } else {
         return $this->xls->getSheetByName($name);
     }
 }
开发者ID:antoineguigan,项目名称:ExcelConnectorBundle,代码行数:16,代码来源:AbstractExcelBuilder.php

示例5: getSheetByIdOrName

 /**
  * Get the sheet by id or name, else get the active sheet
  * @param callable|integer|string $sheetID
  * @param  boolean                $isCallable
  * @throws \PHPExcel_Exception
  * @return \PHPExcel_Worksheet
  */
 protected function getSheetByIdOrName($sheetID, $isCallable = false)
 {
     // If is callback, return the active sheet
     if ($isCallable) {
         return $this->excel->getActiveSheet();
     }
     // If is a string, return the sheet by name
     if (is_string($sheetID)) {
         return $this->excel->getSheetByName($sheetID);
     }
     // Else it should be the sheet index
     return $this->excel->getSheet($sheetID);
 }
开发者ID:nguyenchilong,项目名称:laravel-4.2.x,代码行数:20,代码来源:LaravelExcelReader.php

示例6: open

 /**
  * Opens excel file
  * @return \Meridius\PhpExcel\Reader
  * @throws PhpExcelException
  */
 public function open()
 {
     $reader = PhpOffice_PHPExcel_IOFactory::createReaderForFile($this->file);
     if (count($this->sheetsToLoad) > 0) {
         $reader->setLoadSheetsOnly($this->sheetsToLoad);
     }
     $reader->setReadDataOnly(true);
     $this->excel = $reader->load($this->file);
     if (is_null($this->sheetName)) {
         try {
             $this->activeSheet = $this->excel->getSheet($this->sheetIndex);
         } catch (Exception $e) {
             throw new PhpExcelException("Sheet index '{$this->sheetIndex}' is out of range of excel indexes.");
         }
     } else {
         $this->activeSheet = $this->excel->getSheetByName($this->sheetName);
     }
     if (!$this->activeSheet instanceof PhpOffice_PHPExcel_Worksheet) {
         throw new PhpExcelException("Sheet with name '{$this->sheetName}' does not exist in input excel.");
     }
     $this->mapHeaders();
     return $this;
 }
开发者ID:meridius,项目名称:phpexcel,代码行数:28,代码来源:Reader.php

示例7: hasCellRow

 public function hasCellRow(\PHPExcel $excelObject, $worksheetName, $row, array $values)
 {
     $worksheet = $excelObject->getSheetByName($worksheetName);
     if (!$worksheet) {
         return false;
     }
     $rowIterator = $worksheet->getRowIterator($row);
     if (!$rowIterator->valid()) {
         return false;
     }
     $cellIterator = $rowIterator->current()->getCellIterator();
     $cellIterator->setIterateOnlyExistingCells(false);
     foreach ($cellIterator as $cell) {
         $value = array_shift($values);
         if ($value !== $cell->getValue()) {
             return false;
         }
     }
     return 0 === count($values);
 }
开发者ID:qrz-io,项目名称:ExcelConnectorBundle,代码行数:20,代码来源:ExcelBuilderBehavior.php

示例8: cellExists

 /**
  * Does the cell at a specific coordinate exist?
  *
  * @param string $pCoordinate
  *            Coordinate of the cell
  * @throws PHPExcel_Exception
  * @return boolean
  */
 public function cellExists($pCoordinate = 'A1')
 {
     // Worksheet reference?
     if (strpos($pCoordinate, '!') !== false) {
         $worksheetReference = PHPExcel_Worksheet::extractSheetTitle($pCoordinate, true);
         return $this->_parent->getSheetByName($worksheetReference[0])->cellExists($worksheetReference[1]);
     }
     
     // Named range?
     if ((! preg_match('/^' . PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $pCoordinate, $matches)) && (preg_match('/^' . PHPExcel_Calculation::CALCULATION_REGEXP_NAMEDRANGE . '$/i', $pCoordinate, $matches))) {
         $namedRange = PHPExcel_NamedRange::resolveRange($pCoordinate, $this);
         if ($namedRange !== NULL) {
             $pCoordinate = $namedRange->getRange();
             if ($this->getHashCode() != $namedRange->getWorksheet()->getHashCode()) {
                 if (! $namedRange->getLocalOnly()) {
                     return $namedRange->getWorksheet()->cellExists($pCoordinate);
                 } else {
                     throw new PHPExcel_Exception('Named range ' . $namedRange->getName() . ' is not accessible from within sheet ' . $this->getTitle());
                 }
             }
         } else {
             return false;
         }
     }
     
     // Uppercase coordinate
     $pCoordinate = strtoupper($pCoordinate);
     
     if (strpos($pCoordinate, ':') !== false || strpos($pCoordinate, ',') !== false) {
         throw new PHPExcel_Exception('Cell coordinate can not be a range of cells.');
     } elseif (strpos($pCoordinate, '$') !== false) {
         throw new PHPExcel_Exception('Cell coordinate must not be absolute.');
     } else {
         // Coordinates
         $aCoordinates = PHPExcel_Cell::coordinateFromString($pCoordinate);
         
         // Cell exists?
         return $this->_cellCollection->isDataSet($pCoordinate);
     }
 }
开发者ID:nhatlang19,项目名称:elearningONL,代码行数:48,代码来源:Worksheet.php

示例9: getSheetByName

 /**
  * Gets a sheet by a loose name match unless
  * exactMatch is true. Returns a PHPExcel_Worksheet object
  * if a match is found, false if no match.
  * @param $name
  * @param bool|false $exactMatch
  * @return bool|\PHPExcel_Worksheet
  */
 private function getSheetByName($name, $exactMatch = false)
 {
     if ($exactMatch === false) {
         $name = strtolower($name);
         // determine a case insensitive match
         foreach ($this->workbook->getSheetNames() as $sheet) {
             if (strtolower($sheet) === $name) {
                 $use = $sheet;
                 break;
             }
         }
         if (!isset($use)) {
             return false;
         }
         $this->worksheet = $this->workbook->getSheetByName($use);
     } else {
         if ($this->workbook->sheetNameExists($name)) {
             $this->worksheet = $this->workbook->getSheetByName($name);
         } else {
             return false;
         }
     }
     return $this->worksheet;
 }
开发者ID:buphmin,项目名称:PHPExcelDataFiles,代码行数:32,代码来源:Container.php

示例10: extractNamedRange

 /**
  * Extract range values
  *
  * @param	string				&$pRange	String based range representation
  * @param	PHPExcel_Worksheet	$pSheet		Worksheet
  * @return  mixed				Array of values in range if range contains more than one element. Otherwise, a single value is returned.
  * @param	boolean				$resetLog	Flag indicating whether calculation log should be reset or not
  * @throws	PHPExcel_Calculation_Exception
  */
 public function extractNamedRange(&$pRange = 'A1', PHPExcel_Worksheet $pSheet = NULL, $resetLog = TRUE)
 {
     // Return value
     $returnValue = array();
     //		echo 'extractNamedRange('.$pRange.')<br />';
     if ($pSheet !== NULL) {
         $pSheetName = $pSheet->getTitle();
         //			echo 'Current sheet name is '.$pSheetName.'<br />';
         //			echo 'Range reference is '.$pRange.'<br />';
         if (strpos($pRange, '!') !== false) {
             //				echo '$pRange reference includes sheet reference',PHP_EOL;
             list($pSheetName, $pRange) = PHPExcel_Worksheet::extractSheetTitle($pRange, true);
             //				echo 'New sheet name is '.$pSheetName,PHP_EOL;
             //				echo 'Adjusted Range reference is '.$pRange,PHP_EOL;
             $pSheet = $this->_workbook->getSheetByName($pSheetName);
         }
         // Named range?
         $namedRange = PHPExcel_NamedRange::resolveRange($pRange, $pSheet);
         if ($namedRange !== NULL) {
             $pSheet = $namedRange->getWorksheet();
             //				echo 'Named Range '.$pRange.' (';
             $pRange = $namedRange->getRange();
             $splitRange = PHPExcel_Cell::splitRange($pRange);
             //	Convert row and column references
             if (ctype_alpha($splitRange[0][0])) {
                 $pRange = $splitRange[0][0] . '1:' . $splitRange[0][1] . $namedRange->getWorksheet()->getHighestRow();
             } elseif (ctype_digit($splitRange[0][0])) {
                 $pRange = 'A' . $splitRange[0][0] . ':' . $namedRange->getWorksheet()->getHighestColumn() . $splitRange[0][1];
             }
             //				echo $pRange.') is in sheet '.$namedRange->getWorksheet()->getTitle().'<br />';
             //				if ($pSheet->getTitle() != $namedRange->getWorksheet()->getTitle()) {
             //					if (!$namedRange->getLocalOnly()) {
             //						$pSheet = $namedRange->getWorksheet();
             //					} else {
             //						return $returnValue;
             //					}
             //				}
         } else {
             return PHPExcel_Calculation_Functions::REF();
         }
         // Extract range
         $aReferences = PHPExcel_Cell::extractAllCellReferencesInRange($pRange);
         //			var_dump($aReferences);
         if (!isset($aReferences[1])) {
             //	Single cell (or single column or row) in range
             list($currentCol, $currentRow) = PHPExcel_Cell::coordinateFromString($aReferences[0]);
             $cellValue = NULL;
             if ($pSheet->cellExists($aReferences[0])) {
                 $returnValue[$currentRow][$currentCol] = $pSheet->getCell($aReferences[0])->getCalculatedValue($resetLog);
             } else {
                 $returnValue[$currentRow][$currentCol] = NULL;
             }
         } else {
             // Extract cell data for all cells in the range
             foreach ($aReferences as $reference) {
                 // Extract range
                 list($currentCol, $currentRow) = PHPExcel_Cell::coordinateFromString($reference);
                 //					echo 'NAMED RANGE: $currentCol='.$currentCol.' $currentRow='.$currentRow.'<br />';
                 $cellValue = NULL;
                 if ($pSheet->cellExists($reference)) {
                     $returnValue[$currentRow][$currentCol] = $pSheet->getCell($reference)->getCalculatedValue($resetLog);
                 } else {
                     $returnValue[$currentRow][$currentCol] = NULL;
                 }
             }
         }
         //				print_r($returnValue);
         //			echo '<br />';
     }
     // Return
     return $returnValue;
 }
开发者ID:Princelo,项目名称:bioerp,代码行数:81,代码来源:Calculation.php

示例11: load


//.........这里部分代码省略.........
                         // Next sheet id
                         ++$sheetId;
                     }
                     // Loop through definedNames
                     if ($xmlWorkbook->definedNames) {
                         foreach ($xmlWorkbook->definedNames->definedName as $definedName) {
                             // Extract range
                             $extractedRange = (string) $definedName;
                             $extractedRange = preg_replace('/\'(\\w+)\'\\!/', '', $extractedRange);
                             if (($spos = strpos($extractedRange, '!')) !== false) {
                                 $extractedRange = substr($extractedRange, 0, $spos) . str_replace('$', '', substr($extractedRange, $spos));
                             } else {
                                 $extractedRange = str_replace('$', '', $extractedRange);
                             }
                             // Valid range?
                             if (stripos((string) $definedName, '#REF!') !== false || $extractedRange == '') {
                                 continue;
                             }
                             // Some definedNames are only applicable if we are on the same sheet...
                             if ((string) $definedName['localSheetId'] != '') {
                                 // Local defined name
                                 // Switch on type
                                 switch ((string) $definedName['name']) {
                                     case '_xlnm._FilterDatabase':
                                     case '_xlnm.Print_Titles':
                                     case '_xlnm.Print_Area':
                                         break;
                                     default:
                                         if ($mapSheetId[(int) $definedName['localSheetId']] !== null) {
                                             $range = explode('!', (string) $definedName);
                                             if (count($range) == 2) {
                                                 $range[0] = str_replace("''", "'", $range[0]);
                                                 $range[0] = str_replace("'", "", $range[0]);
                                                 if ($worksheet = $docSheet->getParent()->getSheetByName($range[0])) {
                                                     $extractedRange = str_replace('$', '', $range[1]);
                                                     $scope = $docSheet->getParent()->getSheet($mapSheetId[(int) $definedName['localSheetId']]);
                                                     $excel->addNamedRange(new PHPExcel_NamedRange((string) $definedName['name'], $worksheet, $extractedRange, true, $scope));
                                                 }
                                             }
                                         }
                                         break;
                                 }
                             } else {
                                 if (!isset($definedName['localSheetId'])) {
                                     // "Global" definedNames
                                     $locatedSheet = null;
                                     $extractedSheetName = '';
                                     if (strpos((string) $definedName, '!') !== false) {
                                         // Extract sheet name
                                         $extractedSheetName = PHPExcel_Worksheet::extractSheetTitle((string) $definedName, true);
                                         $extractedSheetName = $extractedSheetName[0];
                                         // Locate sheet
                                         $locatedSheet = $excel->getSheetByName($extractedSheetName);
                                         // Modify range
                                         $range = explode('!', $extractedRange);
                                         $extractedRange = isset($range[1]) ? $range[1] : $range[0];
                                     }
                                     if ($locatedSheet !== NULL) {
                                         $excel->addNamedRange(new PHPExcel_NamedRange((string) $definedName['name'], $locatedSheet, $extractedRange, false));
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if (!$this->_readDataOnly || !empty($this->_loadSheetsOnly)) {
开发者ID:jimlongo56,项目名称:bhouse,代码行数:67,代码来源:Excel2007.php

示例12: loadIntoExisting


//.........这里部分代码省略.........
                                 $styleArray['borders']['diagonal'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->{'Rev-Diagonal'}->attributes());
                                 $styleArray['borders']['diagonaldirection'] = PHPExcel_Style_Borders::DIAGONAL_DOWN;
                             }
                         }
                         if (isset($styleRegion->Style->HyperLink)) {
                             //	TO DO
                             $hyperlink = $styleRegion->Style->HyperLink->attributes();
                         }
                     }
                     //						var_dump($styleArray);
                     //						echo '<br />';
                     $objPHPExcel->getActiveSheet()->getStyle($cellRange)->applyFromArray($styleArray);
                 }
             }
         }
         if (!$this->_readDataOnly && isset($sheet->Cols)) {
             //	Column Widths
             $columnAttributes = $sheet->Cols->attributes();
             $defaultWidth = $columnAttributes['DefaultSizePts'] / 5.4;
             $c = 0;
             foreach ($sheet->Cols->ColInfo as $columnOverride) {
                 $columnAttributes = $columnOverride->attributes();
                 $column = $columnAttributes['No'];
                 $columnWidth = $columnAttributes['Unit'] / 5.4;
                 $hidden = isset($columnAttributes['Hidden']) && $columnAttributes['Hidden'] == '1' ? true : false;
                 $columnCount = isset($columnAttributes['Count']) ? $columnAttributes['Count'] : 1;
                 while ($c < $column) {
                     $objPHPExcel->getActiveSheet()->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($c))->setWidth($defaultWidth);
                     ++$c;
                 }
                 while ($c < $column + $columnCount && $c <= $maxCol) {
                     $objPHPExcel->getActiveSheet()->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($c))->setWidth($columnWidth);
                     if ($hidden) {
                         $objPHPExcel->getActiveSheet()->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($c))->setVisible(false);
                     }
                     ++$c;
                 }
             }
             while ($c <= $maxCol) {
                 $objPHPExcel->getActiveSheet()->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($c))->setWidth($defaultWidth);
                 ++$c;
             }
         }
         if (!$this->_readDataOnly && isset($sheet->Rows)) {
             //	Row Heights
             $rowAttributes = $sheet->Rows->attributes();
             $defaultHeight = $rowAttributes['DefaultSizePts'];
             $r = 0;
             foreach ($sheet->Rows->RowInfo as $rowOverride) {
                 $rowAttributes = $rowOverride->attributes();
                 $row = $rowAttributes['No'];
                 $rowHeight = $rowAttributes['Unit'];
                 $hidden = isset($rowAttributes['Hidden']) && $rowAttributes['Hidden'] == '1' ? true : false;
                 $rowCount = isset($rowAttributes['Count']) ? $rowAttributes['Count'] : 1;
                 while ($r < $row) {
                     ++$r;
                     $objPHPExcel->getActiveSheet()->getRowDimension($r)->setRowHeight($defaultHeight);
                 }
                 while ($r < $row + $rowCount && $r < $maxRow) {
                     ++$r;
                     $objPHPExcel->getActiveSheet()->getRowDimension($r)->setRowHeight($rowHeight);
                     if ($hidden) {
                         $objPHPExcel->getActiveSheet()->getRowDimension($r)->setVisible(false);
                     }
                 }
             }
             while ($r < $maxRow) {
                 ++$r;
                 $objPHPExcel->getActiveSheet()->getRowDimension($r)->setRowHeight($defaultHeight);
             }
         }
         //	Handle Merged Cells in this worksheet
         if (isset($sheet->MergedRegions)) {
             foreach ($sheet->MergedRegions->Merge as $mergeCells) {
                 if (strpos($mergeCells, ':') !== FALSE) {
                     $objPHPExcel->getActiveSheet()->mergeCells($mergeCells);
                 }
             }
         }
         $worksheetID++;
     }
     //	Loop through definedNames (global named ranges)
     if (isset($gnmXML->Names)) {
         foreach ($gnmXML->Names->Name as $namedRange) {
             $name = (string) $namedRange->name;
             $range = (string) $namedRange->value;
             if (stripos($range, '#REF!') !== false) {
                 continue;
             }
             $range = explode('!', $range);
             $range[0] = trim($range[0], "'");
             if ($worksheet = $objPHPExcel->getSheetByName($range[0])) {
                 $extractedRange = str_replace('$', '', $range[1]);
                 $objPHPExcel->addNamedRange(new PHPExcel_NamedRange($name, $worksheet, $extractedRange));
             }
         }
     }
     // Return
     return $objPHPExcel;
 }
开发者ID:AlexandreSGV,项目名称:siteentec,代码行数:101,代码来源:Gnumeric.php

示例13: load


//.........这里部分代码省略.........
                                 $drawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_JPEG);
                                 break;
                             case PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_PNG:
                                 $drawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_PNG);
                                 $drawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_PNG);
                                 break;
                         }
                         $drawing->setWorksheet($this->_phpSheet);
                         $drawing->setCoordinates($spContainer->getStartCoordinates());
                     }
                     break;
                 default:
                     // other object type
                     break;
             }
         }
         // treat SHAREDFMLA records
         if ($this->_version == self::XLS_BIFF8) {
             foreach ($this->_sharedFormulaParts as $cell => $baseCell) {
                 $formula = $this->_getFormulaFromStructure($this->_sharedFormulas[$baseCell], $cell);
                 $this->_phpSheet->getCell($cell)->setValueExplicit('=' . $formula, PHPExcel_Cell_DataType::TYPE_FORMULA);
             }
         }
     }
     // add the named ranges (defined names)
     foreach ($this->_definedname as $definedName) {
         if ($definedName['isBuiltInName']) {
             switch ($definedName['name']) {
                 case pack('C', 0x6):
                     // print area
                     //	in general, formula looks like this: Foo!$C$7:$J$66,Bar!$A$1:$IV$2
                     $ranges = explode(',', $definedName['formula']);
                     // FIXME: what if sheetname contains comma?
                     foreach ($ranges as $range) {
                         // $range should look like this one of these
                         //		Foo!$C$7:$J$66
                         //		Bar!$A$1:$IV$2
                         $explodes = explode('!', $range);
                         if (count($explodes) == 2) {
                             if ($docSheet = $this->_phpExcel->getSheetByName($explodes[0])) {
                                 $extractedRange = $explodes[1];
                                 $extractedRange = str_replace('$', '', $extractedRange);
                                 $docSheet->getPageSetup()->setPrintArea($extractedRange);
                             }
                         }
                     }
                     break;
                 case pack('C', 0x7):
                     // print titles (repeating rows)
                     // Assuming BIFF8, there are 3 cases
                     // 1. repeating rows
                     //		formula looks like this: Sheet!$A$1:$IV$2
                     //		rows 1-2 repeat
                     // 2. repeating columns
                     //		formula looks like this: Sheet!$A$1:$B$65536
                     //		columns A-B repeat
                     // 3. both repeating rows and repeating columns
                     //		formula looks like this: Sheet!$A$1:$B$65536,Sheet!$A$1:$IV$2
                     $ranges = explode(',', $definedName['formula']);
                     // FIXME: what if sheetname contains comma?
                     foreach ($ranges as $range) {
                         // $range should look like this one of these
                         //		Sheet!$A$1:$B$65536
                         //		Sheet!$A$1:$IV$2
                         $explodes = explode('!', $range);
                         if (count($explodes) == 2) {
                             if ($docSheet = $this->_phpExcel->getSheetByName($explodes[0])) {
                                 $extractedRange = $explodes[1];
                                 $extractedRange = str_replace('$', '', $extractedRange);
                                 $coordinateStrings = explode(':', $extractedRange);
                                 if (count($coordinateStrings) == 2) {
                                     list($firstColumn, $firstRow) = PHPExcel_Cell::coordinateFromString($coordinateStrings[0]);
                                     list($lastColumn, $lastRow) = PHPExcel_Cell::coordinateFromString($coordinateStrings[1]);
                                     if ($firstColumn == 'A' and $lastColumn == 'IV') {
                                         // then we have repeating rows
                                         $docSheet->getPageSetup()->setRowsToRepeatAtTop(array($firstRow, $lastRow));
                                     } elseif ($firstRow == 1 and $lastRow == 65536) {
                                         // then we have repeating columns
                                         $docSheet->getPageSetup()->setColumnsToRepeatAtLeft(array($firstColumn, $lastColumn));
                                     }
                                 }
                             }
                         }
                     }
                     break;
             }
         } else {
             // Extract range
             $explodes = explode('!', $definedName['formula']);
             if (count($explodes) == 2) {
                 if ($docSheet = $this->_phpExcel->getSheetByName($explodes[0])) {
                     $extractedRange = $explodes[1];
                     $extractedRange = str_replace('$', '', $extractedRange);
                     $this->_phpExcel->addNamedRange(new PHPExcel_NamedRange((string) $definedName['name'], $docSheet, $extractedRange, false));
                 }
             }
         }
     }
     return $this->_phpExcel;
 }
开发者ID:omusico,项目名称:wildfire_php,代码行数:101,代码来源:Excel5.php

示例14: load


//.........这里部分代码省略.........
                     $blipType = $BSE->getBlipType();
                     $blip = $BSE->getBlip();
                     $ih = imagecreatefromstring($blip->getData());
                     $drawing = new PHPExcel_Worksheet_MemoryDrawing();
                     $drawing->setImageResource($ih);
                     switch ($blipType) {
                         case PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_JPEG:
                             $drawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG);
                             $drawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_JPEG);
                             break;
                         case PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_PNG:
                             $drawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_PNG);
                             $drawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_PNG);
                             break;
                     }
                     $drawing->setWorksheet($this->_phpSheet);
                     $drawing->setCoordinates($spContainer->getStartCoordinates());
                     break;
                 default:
                     // other object type
                     break;
             }
         }
     }
     // add the named ranges (defined names)
     foreach ($this->_definedname as $definedName) {
         if ($definedName['isBuiltInName']) {
             switch ($definedName['name']) {
                 case pack('C', 0x6):
                     // print area
                     //	in general, formula looks like this: Foo!$C$7:$J$66,Bar!$A$1:$IV$2
                     $ranges = explode(',', $definedName['formula']);
                     // FIXME: what if sheetname contains comma?
                     foreach ($ranges as $range) {
                         // $range should look like this one of these
                         //		Foo!$C$7:$J$66
                         //		Bar!$A$1:$IV$2
                         $explodes = explode('!', $range);
                         if (count($explodes) == 2) {
                             if ($docSheet = $this->_phpExcel->getSheetByName($explodes[0])) {
                                 $extractedRange = $explodes[1];
                                 $extractedRange = str_replace('$', '', $extractedRange);
                                 $docSheet->getPageSetup()->setPrintArea($extractedRange);
                             }
                         }
                     }
                     break;
                 case pack('C', 0x7):
                     // print titles (repeating rows)
                     // Assuming BIFF8, there are 3 cases
                     // 1. repeating rows
                     //		formula looks like this: Sheet!$A$1:$IV$2
                     //		rows 1-2 repeat
                     // 2. repeating columns
                     //		formula looks like this: Sheet!$A$1:$B$65536
                     //		columns A-B repeat
                     // 3. both repeating rows and repeating columns
                     //		formula looks like this: Sheet!$A$1:$B$65536,Sheet!$A$1:$IV$2
                     $ranges = explode(',', $definedName['formula']);
                     // FIXME: what if sheetname contains comma?
                     foreach ($ranges as $range) {
                         // $range should look like this one of these
                         //		Sheet!$A$1:$B$65536
                         //		Sheet!$A$1:$IV$2
                         $explodes = explode('!', $range);
                         if (count($explodes) == 2) {
                             if ($docSheet = $this->_phpExcel->getSheetByName($explodes[0])) {
                                 $extractedRange = $explodes[1];
                                 $extractedRange = str_replace('$', '', $extractedRange);
                                 $coordinateStrings = explode(':', $extractedRange);
                                 if (count($coordinateStrings) == 2) {
                                     list($firstColumn, $firstRow) = PHPExcel_Cell::coordinateFromString($coordinateStrings[0]);
                                     list($lastColumn, $lastRow) = PHPExcel_Cell::coordinateFromString($coordinateStrings[1]);
                                     if ($firstColumn == 'A' and $lastColumn == 'IV') {
                                         // then we have repeating rows
                                         $docSheet->getPageSetup()->setRowsToRepeatAtTop(array($firstRow, $lastRow));
                                     } elseif ($firstRow == 1 and $lastRow == 65536) {
                                         // then we have repeating columns
                                         $docSheet->getPageSetup()->setColumnsToRepeatAtLeft(array($firstColumn, $lastColumn));
                                     }
                                 }
                             }
                         }
                     }
                     break;
             }
         } else {
             // Extract range
             $explodes = explode('!', $definedName['formula']);
             if (count($explodes) == 2) {
                 if ($docSheet = $this->_phpExcel->getSheetByName($explodes[0])) {
                     $extractedRange = $explodes[1];
                     $extractedRange = str_replace('$', '', $extractedRange);
                     $this->_phpExcel->addNamedRange(new PHPExcel_NamedRange((string) $definedName['name'], $docSheet, $extractedRange, true));
                 }
             }
         }
     }
     return $this->_phpExcel;
 }
开发者ID:kaantunc,项目名称:MYK-BOR,代码行数:101,代码来源:Excel5.php

示例15: load


//.........这里部分代码省略.........
                                             $blip = $twoCellAnchor->pic->blipFill->children("http://schemas.openxmlformats.org/drawingml/2006/main")->blip;
                                             $xfrm = $twoCellAnchor->pic->spPr->children("http://schemas.openxmlformats.org/drawingml/2006/main")->xfrm;
                                             $outerShdw = $twoCellAnchor->pic->spPr->children("http://schemas.openxmlformats.org/drawingml/2006/main")->effectLst->outerShdw;
                                             $objDrawing = new PHPExcel_Worksheet_Drawing();
                                             $objDrawing->setName((string) self::array_item($twoCellAnchor->pic->nvPicPr->cNvPr->attributes(), "name"));
                                             $objDrawing->setDescription((string) self::array_item($twoCellAnchor->pic->nvPicPr->cNvPr->attributes(), "descr"));
                                             $objDrawing->setPath("zip://{$pFilename}#" . $images[(string) self::array_item($blip->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships"), "embed")], false);
                                             $objDrawing->setCoordinates(PHPExcel_Cell::stringFromColumnIndex($twoCellAnchor->from->col) . ($twoCellAnchor->from->row + 1));
                                             $objDrawing->setOffsetX(PHPExcel_Shared_Drawing::EMUToPixels($twoCellAnchor->from->colOff));
                                             $objDrawing->setOffsetY(PHPExcel_Shared_Drawing::EMUToPixels($twoCellAnchor->from->rowOff));
                                             $objDrawing->setResizeProportional(false);
                                             $objDrawing->setWidth(PHPExcel_Shared_Drawing::EMUToPixels(self::array_item($xfrm->ext->attributes(), "cx")));
                                             $objDrawing->setHeight(PHPExcel_Shared_Drawing::EMUToPixels(self::array_item($xfrm->ext->attributes(), "cy")));
                                             if ($xfrm) {
                                                 $objDrawing->setRotation(PHPExcel_Shared_Drawing::angleToDegrees(self::array_item($xfrm->attributes(), "rot")));
                                             }
                                             if ($outerShdw) {
                                                 $shadow = $objDrawing->getShadow();
                                                 $shadow->setVisible(true);
                                                 $shadow->setBlurRadius(PHPExcel_Shared_Drawing::EMUTopixels(self::array_item($outerShdw->attributes(), "blurRad")));
                                                 $shadow->setDistance(PHPExcel_Shared_Drawing::EMUTopixels(self::array_item($outerShdw->attributes(), "dist")));
                                                 $shadow->setDirection(PHPExcel_Shared_Drawing::angleToDegrees(self::array_item($outerShdw->attributes(), "dir")));
                                                 $shadow->setAlignment((string) self::array_item($outerShdw->attributes(), "algn"));
                                                 $shadow->getColor()->setRGB(self::array_item($outerShdw->srgbClr->attributes(), "val"));
                                                 $shadow->setAlpha(self::array_item($outerShdw->srgbClr->alpha->attributes(), "val") / 1000);
                                             }
                                             $objDrawing->setWorksheet($docSheet);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     // Loop trough definedNames
                     if ($xmlWorkbook->definedNames) {
                         foreach ($xmlWorkbook->definedNames->definedName as $definedName) {
                             // Extract range
                             $extractedRange = (string) $definedName;
                             if (strpos($extractedRange, '!') !== false) {
                                 $extractedRange = substr($extractedRange, strpos($extractedRange, '!') + 1);
                             }
                             $extractedRange = str_replace('$', '', $extractedRange);
                             // Valid range?
                             if (stripos((string) $definedName, '#REF!') !== false || $extractedRange == '') {
                                 continue;
                             }
                             // Some definedNames are only applicable if we are on the same sheet...
                             if ($definedName['localSheetId'] == $sheetId) {
                                 // Switch on type
                                 switch ((string) $definedName['name']) {
                                     case '_xlnm._FilterDatabase':
                                         $docSheet->setAutoFilter($extractedRange);
                                         break;
                                     case '_xlnm.Print_Titles':
                                         // Split $extractedRange
                                         $extractedRange = explode(',', $extractedRange);
                                         // Set print titles
                                         if (isset($extractedRange[0])) {
                                             $docSheet->getPageSetup()->setColumnsToRepeatAtLeft(explode(':', $extractedRange[0]));
                                         }
                                         if (isset($extractedRange[1])) {
                                             $docSheet->getPageSetup()->setRowsToRepeatAtTop(explode(':', $extractedRange[1]));
                                         }
                                         break;
                                     case '_xlnm.Print_Area':
                                         $docSheet->getPageSetup()->setPrintArea($extractedRange);
                                         break;
                                     default:
                                         $excel->addNamedRange(new PHPExcel_NamedRange((string) $definedName['name'], $docSheet, $extractedRange, true));
                                         break;
                                 }
                             } else {
                                 // "Global" definedNames
                                 $locatedSheet = null;
                                 $extractedSheetName = '';
                                 if (strpos((string) $definedName, '!') !== false) {
                                     // Extract sheet name
                                     $extractedSheetName = PHPExcel_Worksheet::extractSheetTitle((string) $definedName);
                                     // Locate sheet
                                     $locatedSheet = $excel->getSheetByName($extractedSheetName);
                                 }
                                 if (!is_null($locatedSheet)) {
                                     $excel->addNamedRange(new PHPExcel_NamedRange((string) $definedName['name'], $locatedSheet, $extractedRange, false));
                                 }
                             }
                         }
                     }
                     // Garbage collect...
                     $docSheet->garbageCollect();
                     // Next sheet id
                     $sheetId++;
                 }
                 if (!$this->_readDataOnly) {
                     $excel->setActiveSheetIndex(intval($xmlWorkbook->bookView->workbookView["activeTab"]));
                 }
                 break;
         }
     }
     return $excel;
 }
开发者ID:abhinay100,项目名称:fengoffice_app,代码行数:101,代码来源:Excel2007.php


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