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


PHP PHPExcel_Worksheet::getCellByColumnAndRow方法代码示例

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


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

示例1: writeCell

 protected function writeCell($value, $column, $row, $config)
 {
     // auto type
     if (!isset($config['type']) || $config['type'] === null) {
         $this->sheet->setCellValueByColumnAndRow($column, $row, $value);
     } elseif ($config['type'] === 'date') {
         if (!is_int($value)) {
             $timestamp = strtotime($value);
         }
         $this->sheet->SetCellValueByColumnAndRow($column, $row, \PHPExcel_Shared_Date::PHPToExcel($timestamp));
         if (!isset($config['styles']['numberformat']['code'])) {
             $config['styles']['numberformat']['code'] = $this->defaultDateFormat;
         }
     } elseif ($config['type'] === 'url') {
         if (isset($config['label'])) {
             if ($config['label'] instanceof \Closure) {
                 // NOTE: calculate label on top level
                 $label = call_user_func($config['label']);
             } else {
                 $label = $config['label'];
             }
         } else {
             $label = $value;
         }
         $urlValid = filter_var($value, FILTER_VALIDATE_URL) !== false;
         if (!$urlValid) {
             $label = '';
         }
         $this->sheet->setCellValueByColumnAndRow($column, $row, $label);
         if ($urlValid) {
             $this->sheet->getCellByColumnAndRow($column, $row)->getHyperlink()->setUrl($value);
         }
     } else {
         $this->sheet->setCellValueExplicitByColumnAndRow($column, $row, $value, $config['type']);
     }
     if (isset($config['styles'])) {
         $this->sheet->getStyleByColumnAndRow($column, $row)->applyFromArray($config['styles']);
     }
 }
开发者ID:alexgx,项目名称:yii2-phpexcel,代码行数:39,代码来源:ExcelDataWriter.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);
     // 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 ($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? 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->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
             $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);
             if ($pSheet->cellExists($coordinate)) {
                 $xfIndex = $pSheet->getCell($coordinate)->getXfIndex();
//.........这里部分代码省略.........
开发者ID:honj51,项目名称:taobaocrm,代码行数:101,代码来源:ReferenceHelper.php

示例3: getNextDataset

 public function getNextDataset()
 {
     $dataset = new Dataset();
     for ($col = 0; $col < $this->highestColumnIndex; ++$col) {
         $cell = $this->worksheet->getCellByColumnAndRow($col, $this->rowPointer);
         $dataset->add($this->header[$col], $cell->getValue());
     }
     $this->rowPointer++;
     return $dataset;
 }
开发者ID:r3h6,项目名称:TYPO3.EXT.data_port,代码行数:10,代码来源:ExcelDataProvider.php

示例4: copyRows

/**
 * 行を完全コピーする
 *
 * http://blog.kotemaru.org/old/2012/04/06.html より
 * @param PHPExcel_Worksheet $sheet
 * @param int $srcRow
 * @param int $dstRow
 * @param int $height
 * @param int $width
 * @throws PHPExcel_Exception
 */
function copyRows(PHPExcel_Worksheet $sheet, $srcRow, $dstRow, $height, $width)
{
    for ($row = 0; $row < $height; $row++) {
        // セルの書式と値の複製
        for ($col = 0; $col < $width; $col++) {
            $cell = $sheet->getCellByColumnAndRow($col, $srcRow + $row);
            $style = $sheet->getStyleByColumnAndRow($col, $srcRow + $row);
            $dstCell = PHPExcel_Cell::stringFromColumnIndex($col) . (string) ($dstRow + $row);
            $sheet->setCellValue($dstCell, $cell->getValue());
            $sheet->duplicateStyle($style, $dstCell);
        }
        // 行の高さ複製。
        $h = $sheet->getRowDimension($srcRow + $row)->getRowHeight();
        $sheet->getRowDimension($dstRow + $row)->setRowHeight($h);
    }
    // セル結合の複製
    // - $mergeCell="AB12:AC15" 複製範囲の物だけ行を加算して復元。
    // - $merge="AB16:AC19"
    foreach ($sheet->getMergeCells() as $mergeCell) {
        $mc = explode(":", $mergeCell);
        $col_s = preg_replace("/[0-9]*/", "", $mc[0]);
        $col_e = preg_replace("/[0-9]*/", "", $mc[1]);
        $row_s = (int) preg_replace("/[A-Z]*/", "", $mc[0]) - $srcRow;
        $row_e = (int) preg_replace("/[A-Z]*/", "", $mc[1]) - $srcRow;
        // 複製先の行範囲なら。
        if (0 <= $row_s && $row_s < $height) {
            $merge = $col_s . (string) ($dstRow + $row_s) . ":" . $col_e . (string) ($dstRow + $row_e);
            $sheet->mergeCells($merge);
        }
    }
}
开发者ID:suin,项目名称:phpexcel-playground,代码行数:42,代码来源:07-output-copy-paste-range.php

示例5: _addCell

 /**
  * 
  * @param DOMElement $element
  * @return PHPExcel_Cell
  */
 protected function _addCell($element, $row = null)
 {
     $text = trim($element->nodeValue);
     $cell = $this->_mainSheet->getCellByColumnAndRow($this->_currentCell, $this->_currentRow);
     if (preg_match('/^\\$ *(\\d{1,3}(\\,\\d{3})*|(\\d+))(\\.\\d{2})?$/', $text)) {
         $currencyCode = PHPExcel_Shared_String::getCurrencyCode();
         $decimalSeparator = PHPExcel_Shared_String::getDecimalSeparator();
         $thousandsSeparator = PHPExcel_Shared_String::getThousandsSeparator();
         $value = (double) trim(str_replace(array($currencyCode, $thousandsSeparator, $decimalSeparator), array('', '', '.'), $text));
         $cell->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_NUMERIC);
         //Style
         $cell->getWorksheet()->getStyle($cell->getCoordinate())->getNumberFormat()->setFormatCode(str_replace('$', $currencyCode, PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE));
     } else {
         $cell->setValueExplicit($text, PHPExcel_Cell_DataType::TYPE_STRING);
     }
     $currentCell = $this->_currentCell;
     if ($element->hasAttribute('colspan')) {
         $colspan = (int) $element->getAttribute('colspan');
         $cellTarget = $this->_currentCell + $colspan - 1;
         $this->_mainSheet->mergeCellsByColumnAndRow($this->_currentCell, $this->_currentRow, $cellTarget, $this->_currentRow);
         $this->_currentCell += $colspan;
     } else {
         $this->_currentCell++;
     }
     if ($element->hasAttribute('rowspan')) {
         $rowSpan = (int) $element->getAttribute('rowspan');
         if ($rowSpan < 2) {
             return $cell;
         }
         $rowTarget = $this->_currentRow + ($rowSpan - 1);
         $this->_mainSheet->mergeCellsByColumnAndRow($currentCell, $this->_currentRow, $currentCell, $rowTarget);
     }
     return $cell;
 }
开发者ID:fredcido,项目名称:simuweb,代码行数:39,代码来源:Excel.php

示例6: doCellStyling

 /**
  * @param $columnNumber
  * @param $columnIdentifier
  * @param $type
  */
 protected function doCellStyling($columnNumber, $columnIdentifier, $type)
 {
     $excelSettings = $this->getExcelSettingsByColumnIdentifier($columnIdentifier);
     if (!is_array($excelSettings[$type])) {
         return;
     }
     $settings = $excelSettings[$type];
     if ($settings['dataType']) {
         $this->activeSheet->getCellByColumnAndRow($columnNumber, $this->rowNumber)->setDataType($settings['dataType']);
     }
     if ($settings['wrapText']) {
         $this->activeSheet->getStyleByColumnAndRow($columnNumber, $this->rowNumber)->getAlignment()->setWrapText($settings['wrapText']);
     }
     if ($settings['vertical']) {
         $this->activeSheet->getStyleByColumnAndRow($columnNumber, $this->rowNumber)->getAlignment()->setVertical($settings['vertical']);
     }
     if ($settings['shrinkToFit']) {
         $this->activeSheet->getStyleByColumnAndRow($columnNumber, $this->rowNumber)->getAlignment()->setShrinkToFit($settings['shrinkToFit']);
     }
     if ($type == 'body') {
         if (!array_key_exists($columnIdentifier, $this->bodyCellStyleCache)) {
             $this->bodyCellStyleCache[$columnIdentifier] = $this->buildStyleArray($settings);
         }
         $this->activeSheet->getStyleByColumnAndRow($columnNumber, $this->rowNumber)->applyFromArray($this->bodyCellStyleCache[$columnIdentifier]);
     } else {
         $this->activeSheet->getStyleByColumnAndRow($columnNumber, $this->rowNumber)->applyFromArray($this->buildStyleArray($settings));
     }
 }
开发者ID:punktde,项目名称:pt_extlist,代码行数:33,代码来源:ExcelListView.php

示例7: validateRow

 /**
  * Проверить не является ли строка заголовком, т.к. ТОРГ12 может содержать несколько заголовков
  *
  * @param int $rowNumber Номер строки
  * @param array $currentRow Содержимое строки
  * @return bool
  */
 private function validateRow($rowNumber, $currentRow)
 {
     $row = [];
     $key = 1;
     for ($col = 0; $col <= $this->highestColumn; $col++) {
         $currentCell = $this->normalizeCellValue($this->worksheet->getCellByColumnAndRow($col, $rowNumber)->getValue());
         // запишем непустые значения в массив для текущей строки
         if ($currentCell) {
             $row[$key++] = $currentCell;
         }
     }
     // пропускаем строку с номерами столбцов
     if (count($row) > 2 && ($row[1] == 1 && $row[2] == 2 && $row[3] == 3)) {
         return false;
     }
     // пропускаем строку без порядкового номера
     if (!intval($currentRow['num'])) {
         return false;
     }
     // пропускаем повторные заголовки (достаточно, если в двух столбцах будет заголовок)
     if (in_array($currentRow['code'], $this->settingsRow['code']) || in_array($currentRow['num'], $this->settingsRow['num'])) {
         return false;
     }
     return true;
 }
开发者ID:golovchanskiy,项目名称:parse-torg12,代码行数:32,代码来源:ParseTorg12.php

示例8: setTimeDataValue

 /**
  * Sets a date/time value at the given col,row location
  *
  * @param $object    the raw data value object
  */
 protected function setTimeDataValue(\SMWTimeValue $object)
 {
     $type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
     $value = \PHPExcel_Shared_Date::stringToExcel(str_replace('T', ' ', $object->getISO8601Date()));
     $this->sheet->getCellByColumnAndRow($this->colNum, $this->rowNum)->setValueExplicit($value, $type);
     if (!$this->styled) {
         $this->sheet->getStyleByColumnAndRow($this->colNum, $this->rowNum)->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_DATE_DDMMYYYY);
     }
 }
开发者ID:cicalese,项目名称:SemanticResultFormats,代码行数:14,代码来源:SRF_Excel.php

示例9: current

 /**
  * Current PHPExcel_Cell
  *
  * @return PHPExcel_Cell
  */
 public function current()
 {
     return $this->_subject->getCellByColumnAndRow($this->_position, $this->_rowIndex);
 }
开发者ID:BGCX262,项目名称:zy-sms-svn-to-git,代码行数:9,代码来源:CellIterator.php

示例10: caPhpExcelGetDateCellContent

/**
 * Get date from Excel sheet for given column and row. Convert Excel date to format acceptable by TimeExpressionParser if necessary.
 * @param PHPExcel_Worksheet $po_sheet The work sheet
 * @param int $pn_row_num row number (zero indexed)
 * @param string|int $pm_col either column number (zero indexed) or column letter ('A', 'BC')
 * @param int $pn_offset Offset to adf to the timestamp (can be used to fix timezone issues or simple to move dates around a little bit)
 * @return string|null the date, if a value exists
 */
function caPhpExcelGetDateCellContent($po_sheet, $pn_row_num, $pm_col, $pn_offset = 0)
{
    if (!is_int($pn_offset)) {
        $pn_offset = 0;
    }
    if (!is_numeric($pm_col)) {
        $pm_col = PHPExcel_Cell::columnIndexFromString($pm_col) - 1;
    }
    $o_val = $po_sheet->getCellByColumnAndRow($pm_col, $pn_row_num);
    $vs_val = trim((string) $o_val);
    if (strlen($vs_val) > 0) {
        $vn_timestamp = PHPExcel_Shared_Date::ExcelToPHP(trim((string) $o_val->getValue())) + $pn_offset;
        if (!($vs_return = caGetLocalizedDate($vn_timestamp, array('dateFormat' => 'iso8601', 'timeOmit' => false)))) {
            $vs_return = $vs_val;
        }
    } else {
        $vs_return = null;
    }
    return $vs_return;
}
开发者ID:idiscussforum,项目名称:providence,代码行数:28,代码来源:importHelpers.php

示例11: caPhpExcelGetRawCell

/**
 * Get raw cell from Excel sheet for given column and row
 * @param PHPExcel_Worksheet $po_sheet The work sheet
 * @param int $pn_row_num row number (zero indexed)
 * @param string|int $pm_col either column number (zero indexed) or column letter ('A', 'BC')
 * @return PHPExcel_Cell|null the cell, if a value exists
 */
function caPhpExcelGetRawCell($po_sheet, $pn_row_num, $pm_col)
{
    if (!is_numeric($pm_col)) {
        $pm_col = PHPExcel_Cell::columnIndexFromString($pm_col) - 1;
    }
    return $po_sheet->getCellByColumnAndRow($pm_col, $pn_row_num);
}
开发者ID:samrahman,项目名称:providence,代码行数:14,代码来源:importHelpers.php

示例12: write_url

 /**
  * Write one url somewhere in the worksheet.
  *
  * @param integer $row    Zero indexed row
  * @param integer $col    Zero indexed column
  * @param string  $url    The url to write
  * @param mixed   $format The XF format for the cell
  */
 public function write_url($row, $col, $url, $format = null)
 {
     $this->worksheet->setCellValueByColumnAndRow($col, $row + 1, $url);
     $this->worksheet->getCellByColumnAndRow($col, $row + 1)->getHyperlink()->setUrl($url);
     $this->apply_format($row, $col, $format);
 }
开发者ID:Gavinthisisit,项目名称:Moodle,代码行数:14,代码来源:excellib.class.php

示例13: lastRow

 function lastRow(PHPExcel_Worksheet $sheet, $indexCellDAY)
 {
     //получаем индекс последней строки в ЛИСТЕ
     $higestRow = $sheet->getHighestRow();
     for ($i = $indexCellDAY; $i <= $higestRow; $i++) {
         $tempRow = $sheet->getCellByColumnAndRow(0, $i)->getFormattedValue();
         if (mb_strtoupper(trim($tempRow)) == "СУББОТА") {
             return ++$i;
         }
     }
 }
开发者ID:ViktorKITP,项目名称:schedule,代码行数:11,代码来源:parserXLS.php

示例14: _getCellValue

 protected function _getCellValue($col, $row)
 {
     $value = $this->_sheet->getCellByColumnAndRow($col, $row)->getFormattedValue();
     return $value;
     //return trim(iconv('windows-1251','utf-8',$value));
 }
开发者ID:ZyManch,项目名称:zbank,代码行数:6,代码来源:BranchDetectorXls.php

示例15: insertNewBefore

 /**
  * Insert a new column or row, updating all possible related data
  *
  * @param   string              $pBefore    Insert before this cell address (e.g. 'A1')
  * @param   integer             $pNumCols   Number of columns to insert/delete (negative values indicate deletion)
  * @param   integer             $pNumRows   Number of rows to insert/delete (negative values indicate deletion)
  * @param   PHPExcel_Worksheet  $pSheet     The worksheet that we're editing
  * @throws  PHPExcel_Exception
  */
 public function insertNewBefore($pBefore = 'A1', $pNumCols = 0, $pNumRows = 0, PHPExcel_Worksheet $pSheet = NULL)
 {
     $remove = $pNumCols < 0 || $pNumRows < 0;
     $aCellCollection = $pSheet->getCellCollection();
     // Get coordinates of $pBefore
     $beforeColumn = 'A';
     $beforeRow = 1;
     list($beforeColumn, $beforeRow) = PHPExcel_Cell::coordinateFromString($pBefore);
     $beforeColumnIndex = PHPExcel_Cell::columnIndexFromString($beforeColumn);
     // 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 && $beforeColumnIndex - 2 + $pNumCols > 0) {
         for ($i = 1; $i <= $highestRow - 1; ++$i) {
             for ($j = $beforeColumnIndex - 1 + $pNumCols; $j <= $beforeColumnIndex - 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 = $beforeColumnIndex - 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 = $remove ? array_shift($aCellCollection) : array_pop($aCellCollection)) {
         $cell = $pSheet->getCell($cellID);
         $cellIndex = PHPExcel_Cell::columnIndexFromString($cell->getColumn());
         if ($cellIndex - 1 + $pNumCols < 0) {
             continue;
         }
         // New coordinates
         $newCoordinates = PHPExcel_Cell::stringFromColumnIndex($cellIndex - 1 + $pNumCols) . ($cell->getRow() + $pNumRows);
         // Should the cell be updated? Move value and cellXf index from one cell to another.
         if ($cellIndex >= $beforeColumnIndex && $cell->getRow() >= $beforeRow) {
             // Update cell styles
             $pSheet->getCell($newCoordinates)->setXfIndex($cell->getXfIndex());
             // 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->getCellCacheController()->deleteCacheData($cellID);
         } 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 && $beforeColumnIndex - 2 > 0) {
         for ($i = $beforeRow; $i <= $highestRow - 1; ++$i) {
             // Style
             $coordinate = PHPExcel_Cell::stringFromColumnIndex($beforeColumnIndex - 2) . $i;
             if ($pSheet->cellExists($coordinate)) {
                 $xfIndex = $pSheet->getCell($coordinate)->getXfIndex();
                 $conditionalStyles = $pSheet->conditionalStylesExists($coordinate) ? $pSheet->getConditionalStyles($coordinate) : false;
                 for ($j = $beforeColumnIndex - 1; $j <= $beforeColumnIndex - 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);
                     }
                 }
             }
//.........这里部分代码省略.........
开发者ID:ljhchshm,项目名称:weixin,代码行数:101,代码来源:ReferenceHelper.php


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