本文整理汇总了PHP中PHPExcel_Worksheet::getTitle方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPExcel_Worksheet::getTitle方法的具体用法?PHP PHPExcel_Worksheet::getTitle怎么用?PHP PHPExcel_Worksheet::getTitle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPExcel_Worksheet
的用法示例。
在下文中一共展示了PHPExcel_Worksheet::getTitle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct(\PHPExcel_Worksheet $worksheet, $parent_filename)
{
$this->name = $this->genName($parent_filename, $worksheet->getTitle());
$row_it = $worksheet->getRowIterator();
$this->header = new \excel2sql\SqlHeader($row_it->current());
$this->entries = array();
for ($row_it->next(); $row_it->valid(); $row_it->next()) {
$rowindex = $row_it->current()->getRowIndex();
$this->entries[] = new \excel2sql\SqlEntry($rowindex, $this->header, $worksheet);
}
}
示例2: loadSheet
/**
*
* @param PHPExcel_Worksheet $sheet
*/
private function loadSheet($sheet)
{
$name = $sheet->getTitle();
$entity_name = "Entity_{$name}";
if (!class_exists($entity_name, true)) {
print "entity class not found. skip. {$entity_name}";
return;
}
// ヘッダ
$rowIterator = $sheet->getRowIterator();
if (!$rowIterator->valid()) {
print "no data. skip. {$entity_name}";
return;
}
$col = array();
$row = $rowIterator->current();
$cellIterator = $row->getCellIterator();
while ($cellIterator->valid()) {
$cell = $cellIterator->current();
$col[] = trim($cell->getValue());
$cellIterator->next();
}
$rowIterator->next();
print "load {$entity_name} .... ";
// データを登録
while ($rowIterator->valid()) {
$row = $rowIterator->current();
$entity = $this->c->getEntity($entity_name);
$cellIterator = $row->getCellIterator();
$i = 0;
while ($cellIterator->valid()) {
$cell = $cellIterator->current();
$prop = $col[$i];
$entity->{$prop} = trim($cell->getValue());
$cellIterator->next();
$i++;
}
$entity->insert();
$rowIterator->next();
}
print $sheet->getHighestRow() - 1 . " rows loaded.\n";
return;
}
示例3: _readBlank
/**
* Read BLANK record
*/
private function _readBlank()
{
$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;
// offset: 0; size: 2; row index
$row = $this->_GetInt2d($recordData, 0);
// offset: 2; size: 2; col index
$col = $this->_GetInt2d($recordData, 2);
$columnString = PHPExcel_Cell::stringFromColumnIndex($col);
// Read cell?
if (!is_null($this->getReadFilter()) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle())) {
// offset: 4; size: 2; XF index
$xfIndex = $this->_GetInt2d($recordData, 4);
// add style information
if (!$this->_readDataOnly) {
$this->_phpSheet->getCell($columnString . ($row + 1))->setXfIndex($this->_mapCellXfIndex[$xfIndex]);
}
}
}
示例4: addExternalSheet
/**
* Add external sheet
*
* @param PHPExcel_Worksheet $pSheet External sheet to add
* @param int|null $iSheetIndex Index where sheet should go (0,1,..., or null for last)
* @throws Exception
* @return PHPExcel_Worksheet
*/
public function addExternalSheet(PHPExcel_Worksheet $pSheet, $iSheetIndex = null)
{
if (!is_null($this->getSheetByName($pSheet->getTitle()))) {
throw new Exception("Workbook already contains a worksheet named '{$pSheet->getTitle()}'. Rename the external sheet first.");
}
// count how many cellXfs there are in this workbook currently, we will need this below
$countCellXfs = count($this->_cellXfCollection);
// copy all the shared cellXfs from the external workbook and append them to the current
foreach ($pSheet->getParent()->getCellXfCollection() as $cellXf) {
$this->addCellXf(clone $cellXf);
}
// move sheet to this workbook
$pSheet->rebindParent($this);
// update the cellXfs
foreach ($pSheet->getCellCollection(false) as $cell) {
$cell->setXfIndex($cell->getXfIndex() + $countCellXfs);
}
return $this->addSheet($pSheet, $iSheetIndex);
}
示例5: removeNamedRange
/**
* Remove named range
*
* @param string $namedRange
* @param PHPExcel_Worksheet|null $pSheet Scope: use null for global scope.
* @return PHPExcel
*/
public function removeNamedRange($namedRange, PHPExcel_Worksheet $pSheet = null)
{
if ($pSheet === null) {
if (isset($this->namedRanges[$namedRange])) {
unset($this->namedRanges[$namedRange]);
}
} else {
if (isset($this->namedRanges[$pSheet->getTitle() . '!' . $namedRange])) {
unset($this->namedRanges[$pSheet->getTitle() . '!' . $namedRange]);
}
}
return $this;
}
示例6: 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;
}
示例7: _writeSheetPr
/**
* Write SheetPr
*
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
* @param PHPExcel_Worksheet $pSheet Worksheet
* @throws PHPExcel_Writer_Exception
*/
private function _writeSheetPr(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
{
// sheetPr
$objWriter->startElement('sheetPr');
//$objWriter->writeAttribute('codeName', $pSheet->getTitle());
if ($pSheet->getParent()->hasMacros()) {
//if the workbook have macros, we need to have codeName for the sheet
if ($pSheet->hasCodeName() == false) {
$pSheet->setCodeName($pSheet->getTitle());
}
$objWriter->writeAttribute('codeName', $pSheet->getCodeName());
}
$autoFilterRange = $pSheet->getAutoFilter()->getRange();
if (!empty($autoFilterRange)) {
$objWriter->writeAttribute('filterMode', 1);
$pSheet->getAutoFilter()->showHideRows();
}
// tabColor
if ($pSheet->isTabColorSet()) {
$objWriter->startElement('tabColor');
$objWriter->writeAttribute('rgb', $pSheet->getTabColor()->getARGB());
$objWriter->endElement();
}
// outlinePr
$objWriter->startElement('outlinePr');
$objWriter->writeAttribute('summaryBelow', $pSheet->getShowSummaryBelow() ? '1' : '0');
$objWriter->writeAttribute('summaryRight', $pSheet->getShowSummaryRight() ? '1' : '0');
$objWriter->endElement();
// pageSetUpPr
if ($pSheet->getPageSetup()->getFitToPage()) {
$objWriter->startElement('pageSetUpPr');
$objWriter->writeAttribute('fitToPage', '1');
$objWriter->endElement();
}
$objWriter->endElement();
}
示例8: writeValues
/**
* Writes a row of values
*
* @param \PHPExcel_Worksheet $worksheet
* @param array $data An array of values with column indexes as keys
*/
protected function writeValues(\PHPExcel_Worksheet $worksheet, array $data)
{
$worksheetName = $worksheet->getTitle();
$row = $this->rowIndexes[$worksheetName];
foreach ($this->labels[$worksheet->getTitle()] as $column => $label) {
if (isset($data[$label])) {
$worksheet->setCellValueByColumnAndRow($column, $row, $data[$label]);
}
}
$this->rowIndexes[$worksheetName]++;
}
示例9: count
/**
* Add a new worksheet to the Excel workbook.
* If no name is given the name of the worksheet will be Sheeti$i, with
* $i in [1..].
*
* @access public
* @param PHPExcel_Worksheet $phpSheet
* @param array $xfIndexes
* @return mixed reference to a worksheet object on success
*/
function &addWorksheet($phpSheet = null, &$xfIndexes)
{
$name = $phpSheet->getTitle();
$index = count($this->_worksheets);
// Check that sheetname is <= 31 chars (Excel limit before BIFF8).
if ($this->_BIFF_version != 0x600) {
if (strlen($name) > 31) {
throw new Exception("Sheetname {$name} must be <= 31 chars");
}
}
$total_worksheets = count($this->_worksheets);
$worksheet = new PHPExcel_Writer_Excel5_Worksheet($this->_BIFF_version, $this->_str_total, $this->_str_unique, $this->_str_table, $this->_parser, $this->_tmp_dir, $phpSheet, $xfIndexes);
$this->_worksheets[$index] =& $worksheet;
// Store ref for iterator
$this->_parser->setExtSheet($name, $index);
// Register worksheet name with parser
// for BIFF8
if ($this->_BIFF_version == 0x600) {
$supbook_index = 0x0;
$ref = pack('vvv', $supbook_index, $total_worksheets, $total_worksheets);
$this->_parser->_references[] = $ref;
// Register reference with parser
}
return $worksheet;
}
示例10: ParseWorksheetWithIfc
/**
*
* @param PHPExcel_Worksheet $worksheet
* @param InterfaceObject $ifc
* @return void
*/
private function ParseWorksheetWithIfc($worksheet, $ifc)
{
/* Use interface name as worksheet name. Format for content is as follows:
#1 <srcConcept> | <ifc label x> | <ifc label y> | <etc>
#2 <srcAtomA> | <tgtAtom1> | <tgtAtom2> | <etc>
#3 <srcAtomB> | <tgtAtom3> | <tgtAtom4> | <etc>
*/
$highestrow = $worksheet->getHighestRow();
$highestcolumn = $worksheet->getHighestColumn();
$highestcolumnnr = PHPExcel_Cell::columnIndexFromString($highestcolumn);
$leftConcept = Concept::getConceptByLabel((string) $worksheet->getCell('A1'));
if ($leftConcept != $ifc->tgtConcept) {
throw new Exception("Target concept of interface '{$ifc->path}' does not match concept specified in cell {$worksheet->getTitle()}:A1", 500);
}
// Parse other columns of first row
$header = array();
for ($columnnr = 1; $columnnr < $highestcolumnnr; $columnnr++) {
$columnletter = PHPExcel_Cell::stringFromColumnIndex($columnnr);
$cell = $worksheet->getCell($columnletter . '1');
$cellvalue = (string) $cell->getCalculatedValue();
if ($cellvalue == '') {
$header[$columnletter] = null;
} else {
$subIfc = $ifc->getSubinterfaceByLabel($cellvalue);
if (!$subIfc->crudU || !$subIfc->relation) {
throw new Exception("Update not allowed/possible for {$subIfc->label} as specified in cell {$columnletter}1", 403);
}
$header[$columnletter] = $subIfc;
}
}
for ($row = 2; $row <= $highestrow; $row++) {
$firstCol = (string) $worksheet->getCell('A' . $row)->getCalculatedValue();
if ($firstCol == '') {
continue;
} elseif ($firstCol == '_NEW') {
if (!$ifc->crudC) {
throw new Exception("Trying to create new atom in cell A{$row}. This is not allowed.", 403);
}
$leftAtom = $leftConcept->createNewAtom()->addAtom();
} else {
$leftAtom = new Atom($firstCol, $leftConcept);
if (!$leftAtom->atomExists() && !$ifc->crudC) {
throw new Exception("Trying to create new {$leftConcept} in cell A{$row}. This is not allowed.", 403);
}
$leftAtom->addAtom();
}
for ($columnnr = 1; $columnnr < $highestcolumnnr; $columnnr++) {
$columnletter = PHPExcel_Cell::stringFromColumnIndex($columnnr);
if (is_null($header[$columnletter])) {
continue;
}
// skip this column.
$cell = $worksheet->getCell($columnletter . $row);
$cellvalue = (string) $cell->getCalculatedValue();
if ($cellvalue == '') {
continue;
}
// skip if not value provided
// overwrite $cellvalue in case of datetime
// the @ is a php indicator for a unix timestamp (http://php.net/manual/en/datetime.formats.compound.php), later used for typeConversion
if (PHPExcel_Shared_Date::isDateTime($cell) && !empty($cellvalue)) {
$cellvalue = '@' . (string) PHPExcel_Shared_Date::ExcelToPHP($cellvalue);
}
$rightAtom = new Atom($cellvalue, $header[$columnletter]->tgtConcept);
if (!$rightAtom->atomExists() && !$header[$columnletter]->crudC) {
throw new Exception("Trying to create new {$header[$columnletter]->tgtConcept} in cell {$columnletter}{$row}. This is not allowed.", 403);
}
$header[$columnletter]->relation()->addLink($leftAtom, $rightAtom, $header[$columnletter]->relationIsFlipped, 'ExcelImport');
}
}
}
示例11: addChart2
private function addChart2(\PHPExcel $ea, \PHPExcel_Worksheet $ews)
{
$title = new \PHPExcel_Chart_Title($ews->getTitle());
$dsl = array(new \PHPExcel_Chart_DataSeriesValues('String', 'Data!$D$1', NULL, 1), new \PHPExcel_Chart_DataSeriesValues('String', 'Data!$E$1', NULL, 1));
$xal = array(new \PHPExcel_Chart_DataSeriesValues('String', 'Data!$F$2:$F$91', NULL, 90));
$dsv = array(new \PHPExcel_Chart_DataSeriesValues('Number', 'Data!$D$2:$D$91', NULL, 90), new \PHPExcel_Chart_DataSeriesValues('Number', 'Data!$E$2:$E$91', NULL, 90));
$ds = new \PHPExcel_Chart_DataSeries(\PHPExcel_Chart_DataSeries::TYPE_LINECHART, \PHPExcel_Chart_DataSeries::GROUPING_STANDARD, range(0, count($dsv) - 1), $dsl, $xal, $dsv);
$pa = new \PHPExcel_Chart_PlotArea(NULL, array($ds));
// Set legend
$legend = new \PHPExcel_Chart_Legend(\PHPExcel_Chart_Legend::POSITION_RIGHT, NULL, false);
$chart = new \PHPExcel_Chart('Chart1', $title, $legend, $pa, true, 0, NULL, NULL);
$chart->setTopLeftPosition('I1');
$chart->setBottomRightPosition('AA21');
$ews->addChart($chart);
return $chart;
}
示例12: 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();
if ($pSheet !== null) {
$pSheetName = $pSheet->getTitle();
if (strpos($pRange, '!') !== false) {
list($pSheetName, $pRange) = PHPExcel_Worksheet::extractSheetTitle($pRange, true);
$pSheet = $this->_workbook->getSheetByName($pSheetName);
}
// Named range?
$namedRange = PHPExcel_NamedRange::resolveRange($pRange, $pSheet);
if ($namedRange !== null) {
$pSheet = $namedRange->getWorksheet();
$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];
}
} else {
return PHPExcel_Calculation_Functions::REF();
}
// Extract range
$aReferences = PHPExcel_Cell::extractAllCellReferencesInRange($pRange);
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);
$cellValue = null;
if ($pSheet->cellExists($reference)) {
$returnValue[$currentRow][$currentCol] = $pSheet->getCell($reference)->getCalculatedValue($resetLog);
} else {
$returnValue[$currentRow][$currentCol] = null;
}
}
}
}
// Return
return $returnValue;
}
示例13: _writeSheetPr
/**
* Write SheetPr
*
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
* @param PHPExcel_Worksheet $pSheet Worksheet
* @throws Exception
*/
private function _writeSheetPr(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
{
// sheetPr
$objWriter->startElement('sheetPr');
$objWriter->writeAttribute('codeName', $pSheet->getTitle());
// outlinePr
$objWriter->startElement('outlinePr');
$objWriter->writeAttribute('summaryBelow', $pSheet->getShowSummaryBelow() ? '1' : '0');
$objWriter->writeAttribute('summaryRight', $pSheet->getShowSummaryRight() ? '1' : '0');
$objWriter->endElement();
// pageSetUpPr
if (!is_null($pSheet->getPageSetup()->getFitToHeight()) || !is_null($pSheet->getPageSetup()->getFitToWidth())) {
$objWriter->startElement('pageSetUpPr');
$objWriter->writeAttribute('fitToPage', '1');
$objWriter->endElement();
}
$objWriter->endElement();
}
示例14: addExternalSheet
/**
* 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);
}
示例15: 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)
{
$aCellCollection = $pSheet->getCellCollection();
// Get coordinates of $pBefore
$beforeColumn = 'A';
$beforeRow = 1;
list($beforeColumn, $beforeRow) = PHPExcel_Cell::coordinateFromString($pBefore);
// Clear cells if we are removing columns or rows
$highestColumn = $pSheet->getHighestColumn();
$highestRow = $pSheet->getHighestRow();
// 1. Clear column strips if we are removing columns
if ($pNumCols < 0 && PHPExcel_Cell::columnIndexFromString($beforeColumn) - 2 + $pNumCols > 0) {
for ($i = 1; $i <= $highestRow - 1; ++$i) {
for ($j = PHPExcel_Cell::columnIndexFromString($beforeColumn) - 1 + $pNumCols; $j <= PHPExcel_Cell::columnIndexFromString($beforeColumn) - 2; ++$j) {
$coordinate = PHPExcel_Cell::stringFromColumnIndex($j) . $i;
$pSheet->removeConditionalStyles($coordinate);
if ($pSheet->cellExists($coordinate)) {
$pSheet->getCell($coordinate)->setValueExplicit('', PHPExcel_Cell_DataType::TYPE_NULL);
$pSheet->getCell($coordinate)->setXfIndex(0);
}
}
}
}
// 2. Clear row strips if we are removing rows
if ($pNumRows < 0 && $beforeRow - 1 + $pNumRows > 0) {
for ($i = PHPExcel_Cell::columnIndexFromString($beforeColumn) - 1; $i <= PHPExcel_Cell::columnIndexFromString($highestColumn) - 1; ++$i) {
for ($j = $beforeRow + $pNumRows; $j <= $beforeRow - 1; ++$j) {
$coordinate = PHPExcel_Cell::stringFromColumnIndex($i) . $j;
$pSheet->removeConditionalStyles($coordinate);
if ($pSheet->cellExists($coordinate)) {
$pSheet->getCell($coordinate)->setValueExplicit('', PHPExcel_Cell_DataType::TYPE_NULL);
$pSheet->getCell($coordinate)->setXfIndex(0);
}
}
}
}
// Loop through cells, bottom-up, and change cell coordinates
while ($cellID = $pNumCols < 0 || $pNumRows < 0 ? array_shift($aCellCollection) : array_pop($aCellCollection)) {
$cell = $pSheet->getCell($cellID);
// New coordinates
$newCoordinates = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($cell->getColumn()) - 1 + $pNumCols) . ($cell->getRow() + $pNumRows);
// Should the cell be updated? Move value and cellXf index from one cell to another.
if (PHPExcel_Cell::columnIndexFromString($cell->getColumn()) >= PHPExcel_Cell::columnIndexFromString($beforeColumn) && $cell->getRow() >= $beforeRow) {
// Update cell styles
$pSheet->getCell($newCoordinates)->setXfIndex($cell->getXfIndex());
$cell->setXfIndex(0);
// Insert this cell at its new location
if ($cell->getDataType() == PHPExcel_Cell_DataType::TYPE_FORMULA) {
// Formula should be adjusted
$pSheet->getCell($newCoordinates)->setValue($this->updateFormulaReferences($cell->getValue(), $pBefore, $pNumCols, $pNumRows, $pSheet->getTitle()));
} else {
// Formula should not be adjusted
$pSheet->getCell($newCoordinates)->setValue($cell->getValue());
}
// Clear the original cell
$pSheet->getCell($cell->getCoordinate())->setValue('');
} else {
/* We don't need to update styles for rows/columns before our insertion position,
but we do still need to adjust any formulae in those cells */
if ($cell->getDataType() == PHPExcel_Cell_DataType::TYPE_FORMULA) {
// Formula should be adjusted
$cell->setValue($this->updateFormulaReferences($cell->getValue(), $pBefore, $pNumCols, $pNumRows, $pSheet->getTitle()));
}
}
}
// 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
$coordinate = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($beforeColumn) - 2) . $i;
if ($pSheet->cellExists($coordinate)) {
$xfIndex = $pSheet->getCell($coordinate)->getXfIndex();
$conditionalStyles = $pSheet->conditionalStylesExists($coordinate) ? $pSheet->getConditionalStyles($coordinate) : false;
for ($j = PHPExcel_Cell::columnIndexFromString($beforeColumn) - 1; $j <= PHPExcel_Cell::columnIndexFromString($beforeColumn) - 2 + $pNumCols; ++$j) {
$pSheet->getCellByColumnAndRow($j, $i)->setXfIndex($xfIndex);
if ($conditionalStyles) {
$cloned = array();
foreach ($conditionalStyles as $conditionalStyle) {
$cloned[] = clone $conditionalStyle;
}
$pSheet->setConditionalStyles(PHPExcel_Cell::stringFromColumnIndex($j) . $i, $cloned);
}
}
}
}
}
if ($pNumRows > 0 && $beforeRow - 1 > 0) {
for ($i = PHPExcel_Cell::columnIndexFromString($beforeColumn) - 1; $i <= PHPExcel_Cell::columnIndexFromString($highestColumn) - 1; ++$i) {
// Style
$coordinate = PHPExcel_Cell::stringFromColumnIndex($i) . ($beforeRow - 1);
//.........这里部分代码省略.........