本文整理汇总了PHP中PHPExcel_Worksheet::rangeToArray方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPExcel_Worksheet::rangeToArray方法的具体用法?PHP PHPExcel_Worksheet::rangeToArray怎么用?PHP PHPExcel_Worksheet::rangeToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPExcel_Worksheet
的用法示例。
在下文中一共展示了PHPExcel_Worksheet::rangeToArray方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRow
/**
* Returns row array with offsets as keys.
* @return array integer => mixed
*/
protected function getRow()
{
// Try to return cached value
if ($this->position == $this->lastRowPosition) {
return $this->lastRow;
}
$range = sprintf('A%d:%s%1$d', $this->position, \PHPExcel_Cell::stringFromColumnIndex($this->colsCount - 1));
$rows = $this->sheet->rangeToArray($range);
$row = array_pop($rows);
// Cache value
$this->lastRowPosition = $this->position;
$this->lastRow = $row;
return $row;
}
示例2: populateNamedRanges
private function populateNamedRanges(\PHPExcel_Worksheet $templateSheet)
{
$template = $templateSheet->getParent();
$excelNamedRanges = array_change_key_case($template->getNamedRanges(), CASE_UPPER);
if (!isset($excelNamedRanges['ROOT'])) {
throw new \InvalidArgumentException("Missing Named-Range: 'ROOT'");
}
$namedRanges = [];
/** @var \PHPExcel_NamedRange $excelNamedRange */
foreach ($excelNamedRanges as $name => $excelNamedRange) {
$namedRanges[$name] = [];
foreach ($templateSheet->rangeToArray($excelNamedRange->getRange(), null, false, true, true) as $rowNum => $row) {
$namedRanges[$name][$rowNum - 1] = [];
foreach ($row as $col => $cellValue) {
$colNum = \PHPExcel_Cell::columnIndexFromString($col);
$templateCor = $col . $rowNum;
$style = $this->getStyleOfCell($templateSheet, $templateCor);
$namedRanges[$name][$rowNum - 1][$colNum - 1] = ['value' => $cellValue, 'style' => $style];
}
}
}
$this->logger->debug('Populated named ranges', array_keys($namedRanges));
return $namedRanges;
}
示例3: setHeaderRowNumber
/**
* Set header row number
*
* @param integer $rowNumber Number of the row that contains column header names
*/
public function setHeaderRowNumber($rowNumber)
{
$rowNumber++;
$this->headerRowNumber = $rowNumber;
$res = $this->worksheet->rangeToArray(sprintf('A%d:%s%d', $rowNumber, $this->maxColumn, $rowNumber));
$this->setColumnHeaders(current($res));
$this->pointer = $rowNumber;
}
示例4: _calculateTopTenValue
private function _calculateTopTenValue($columnID, $startRow, $endRow, $ruleType, $ruleValue)
{
$range = $columnID . $startRow . ':' . $columnID . $endRow;
$dataValues = PHPExcel_Calculation_Functions::flattenArray($this->_workSheet->rangeToArray($range, NULL, TRUE, FALSE));
$dataValues = array_filter($dataValues);
if ($ruleType == PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_TOPTEN_TOP) {
rsort($dataValues);
} else {
sort($dataValues);
}
return array_pop(array_slice($dataValues, 0, $ruleValue));
}
示例5: prepararArchivo
/**
*
* @param PHPExcel_Worksheet $hoja
* @param int $pk representa el índice de la columna en el archivo de excel que está asociada con la llave primaria de la tabla
* @return string rerpesenta el nombre la ruta del archivo creado. Si no se pudo crear el archivo se regresa otra cosa :p
*/
function prepararArchivo($hoja, $pk = false, $incluirPrimeraFila = false)
{
$objetoExcel = new PHPExcel();
$hojaInsertar = $objetoExcel->getSheet(0);
$hojaInsertar->setTitle('Insertar');
if ($objetoExcel->getSheetCount() > 1) {
$hojaActualizar = $objetoExcel->getSheet(1);
$hojaActualizar->setTitle('Actualizar');
} else {
$hojaActualizar = new PHPExcel_Worksheet();
$hojaActualizar->setTitle('Actualizar');
$objetoExcel->addSheet($hojaActualizar);
}
$rango = $hoja->calculateWorksheetDataDimension();
if (!$incluirPrimeraFila) {
$rango[1] = '2';
}
$contenidoExcel = $hoja->rangeToArray($rango);
$datos = array();
$datos['insertar'] = array();
$datos['actualizar'] = array();
if ($pk) {
$db = new DbConnection();
$db->abrirConexion();
$llavePrimaria = $_SESSION['pk'];
foreach ($contenidoExcel as $fila) {
$existe = $db->existeRegistro($_SESSION['tabla'], $llavePrimaria, $fila[$pk]);
if ($existe) {
$datos['actualizar'][] = $fila;
} else {
$datos['insertar'][] = $fila;
}
}
$db->cerrarConexion();
} else {
foreach ($contenidoExcel as $fila) {
$datos['insertar'][] = $fila;
}
}
$hojaInsertar->fromArray($datos['insertar'], null, 'A1', true);
$hojaActualizar->fromArray($datos['actualizar'], null, 'A1', true);
$escritorExcel = PHPExcel_IOFactory::createWriter($objetoExcel, 'Excel2007');
$escritorExcel->save('excelTmp/tmp_import_upload.xlsx');
return 'excelTmp/tmp_import_upload.xlsx';
}