文件名称:好用的phpExcel
文件大小:5.59MB
文件格式:ZIP
更新时间:2012-04-17 06:15:58
phpExcel
好用的phpExcel_workSheetCollection = array(); $this->_workSheetCollection[] = new PHPExcel_Worksheet($this); $this->_activeSheetIndex = 0; // Create document properties $this->_properties = new PHPExcel_DocumentProperties(); // Create document security $this->_security = new PHPExcel_DocumentSecurity(); // Set named ranges $this->_namedRanges = array(); } /** * Get properties * * @return PHPExcel_DocumentProperties */ public function getProperties() { return $this->_properties; } /** * Set properties * * @param PHPExcel_DocumentProperties $pValue */ public function setProperties(PHPExcel_DocumentProperties $pValue) { $this->_properties = $pValue; } /** * Get security * * @return PHPExcel_DocumentSecurity */ public function getSecurity() { return $this->_security; } /** * Set security * * @param PHPExcel_DocumentSecurity $pValue */ public function setSecurity(PHPExcel_DocumentSecurity $pValue) { $this->_security = $pValue; } /** * Get active sheet * * @return PHPExcel_Worksheet */ public function getActiveSheet() { return $this->_workSheetCollection[$this->_activeSheetIndex]; } /** * Create sheet and add it to this workbook * * @return PHPExcel_Worksheet */ public function createSheet() { $newSheet = new PHPExcel_Worksheet($this); $this->addSheet($newSheet); return $newSheet; } /** * Add sheet * * @param PHPExcel_Worksheet $pSheet * @throws Exception */ public function addSheet(PHPExcel_Worksheet $pSheet = null) { $this->_workSheetCollection[] = $pSheet; } /** * Remove sheet by index * * @param int $pIndex Active sheet index * @throws Exception */ public function removeSheetByIndex($pIndex = 0) { if ($pIndex > count($this->_workSheetCollection) - 1) { throw new Exception("Sheet index is out of bounds."); } else { array_splice($this->_workSheetCollection, $pIndex, 1); } } /** * Get sheet by index * * @param int $pIndex Sheet index * @return PHPExcel_Worksheet * @throws Exception */ public function getSheet($pIndex = 0) { if ($pIndex > count($this->_workSheetCollection) - 1) { throw new Exception("Sheet index is out of bounds."); } else { return $this->_workSheetCollection[$pIndex]; } } /** * Get all sheets * * @return PHPExcel_Worksheet[] */ public function getAllSheets() { return $this->_workSheetCollection; } /** * Get sheet by name * * @param string $pName Sheet name * @return PHPExcel_Worksheet * @throws Exception */ public function getSheetByName($pName = '') { $worksheetCount = count($this->_workSheetCollection); for ($i = 0; $i < $worksheetCount; ++$i) { if ($this->_workSheetCollection[$i]->getTitle() == $pName) { return $this->_workSheetCollection[$i]; } } return null; } /** * Get index for sheet * * @param PHPExcel_Worksheet $pSheet * @return Sheet index * @throws Exception */ public function getIndex(PHPExcel_Worksheet $pSheet) { foreach ($this->_workSheetCollection as $key => $value) { if ($value->getHashCode() == $pSheet->getHashCode()) { return $key; } } } /** * Get sheet count * * @return int */ public function getSheetCount() { return count($this->_workSheetCollection); } /** * Get active sheet index * * @return int Active sheet index */ public function getActiveSheetIndex() { return $this->_activeSheetIndex; } /** * Set active sheet index * * @param int $pIndex Active sheet index * @throws Exception */ public function setActiveSheetIndex($pIndex = 0) { if ($pIndex > count($this->_workSheetCollection) - 1) { throw new Exception("Active sheet index is out of bounds."); } else { $this->_activeSheetIndex = $pIndex; } } /** * Get sheet names * * @return string[] */ public function getSheetNames() { $returnValue = array(); $worksheetCount = $this->getSheetCount(); for ($i = 0; $i < $worksheetCount; ++$i) { array_push($returnValue, $this->getSheet($i)->getTitle()); } return $returnValue; } /** * Add external sheet * * @param PHPExcel_Worksheet $pSheet External sheet to add * @throws Exception */ public function addExternalSheet(PHPExcel_Worksheet $pSheet) { if (!is_null($this->getSheetByName($pSheet->getTitle()))) { throw new Exception("Workbook already contains a worksheet named '{$pSheet->getTitle()}'. Rename the external sheet first."); } $pSheet->rebindParent($this); $this->addSheet($pSheet); } /** * Get named ranges * * @return PHPExcel_NamedRange[] */ public function getNamedRanges() { return $this->_namedRanges; } /** * Add named range * * @param PHPExcel_NamedRange $namedRange */ public function addNamedRange(PHPExcel_NamedRange $namedRange) { $this->_namedRanges[$namedRange->getName()] = $namedRange; } /** * Get named range * * @param string $namedRange */ public function getNamedRange($namedRange) { if ($namedRange != '' && !is_null($namedRange) && @isset($this->_namedRanges[$namedRange])) { return $this->_namedRanges[$namedRange]; } return null; } /** * Remove named range * * @param string $namedRange */ public function removeNamedRange($namedRange) { if ($namedRange != '' && !is_null($namedRange) && @isset($this->_namedRanges[$namedRange])) { unset($this->_namedRanges[$namedRange]); } } /** * Get worksheet iterator * * @return PHPExcel_WorksheetIterator */ public function getWorksheetIterator() { return new PHPExcel_WorksheetIterator($this); } /** * Copy workbook (!= clone!) * * @return PHPExcel */ public function copy() { $copied = clone $this; $worksheetCount = count($this->_workSheetCollection); for ($i = 0; $i < $worksheetCount; ++$i) { $this->_workSheetCollection[$i] = $this->_workSheetCollection[$i]->copy(); $this->_workSheetCollection[$i]->rebindParent($this); } return $copied; } /** * Implement PHP __clone to create a deep clone, not just a shallow copy. */ public function __clone() { $vars = get_object_vars($this); foreach ($vars as $key => $value) { if (is_object($value)) { $this->$key = clone $value; } else { $this->$key = $value; } } } }