简体   繁体   English

PHPExcel:阅读工作表的一部分

[英]PHPExcel: read part of the sheet

How to get part of the sheet, for example, only rows from 1 to 10 or from 20 to 30 etc? 如何获得工作表的一部分,例如,仅从1到10或从20到30等的行? Now im using this: 现在即时通讯使用此:

public function GetArray($from = false, $to = false) {
    $rowIterator = $this->objPHPExcel->getRowIterator();
    foreach ($rowIterator as $id=>$row) {

        if($from)
            if($id < $from) continue;

        if($to)
            if($id > $to) break;

        $cellIterator = $row->getCellIterator();
        foreach ($cellIterator as $cell) {
            $arResult[$id][] = trim($cell->getCalculatedValue());
        }
    }
    return $arResult;
}

But im think this is not the best solution. 但是我认为这不是最好的解决方案。

Easiest method is to use the Worksheet's rangeToArray() method. 最简单的方法是使用工作表的rangeToArray()方法。

/**
 * Create array from a range of cells
 *
 * @param   string    $pRange              Range of cells (i.e. "A1:B10"),
 *                                             or just one cell (i.e. "A1")
 * @param   mixed     $nullValue           Value returned in the array entry if a cell
 *                                             doesn't exist
 * @param   boolean   $calculateFormulas   Should formulas be calculated?
 * @param   boolean   $formatData          Should formatting be applied to cell values?
 * @param   boolean   $returnCellRef       False - Return a simple array of rows and
 *                                             columns indexed by number counting from
 *                                             zero
 *                                         True - Return rows and columns indexed by
 *                                             their actual row and column IDs
 * @return array
 */

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM