php 如何在 PHPExcel 中获取一系列单元格?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18203595/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I get a range of cells in PHPExcel?
提问by hitautodestruct
I am using PHPExcel to read some data from an xls
file.
我正在使用 PHPExcel 从xls
文件中读取一些数据。
I want to get a couple of cells at once, say: A6 - A11.
我想一次得到几个单元格,比如:A6 - A11。
I know I can use $cell = $objPHPExcel->setActiveSheetIndex(0)->getCell('A6');
to get a single cell, and I could probably loop through an array and get each cell in my range.
我知道我可以$cell = $objPHPExcel->setActiveSheetIndex(0)->getCell('A6');
用来获取单个单元格,我可能可以遍历一个数组并获取我范围内的每个单元格。
But, isn't there a simpler method to get a range of cells something like getCellRange('A6:A11')
?
但是,难道没有一种更简单的方法来获取一系列单元格getCellRange('A6:A11')
吗?
回答by Mark Baker
There is, the rangeToArray()
method:
有,rangeToArray()
方法:
$objPHPExcel->setActiveSheetIndex(0)->rangeToArray('A1:C3');
Wondering why I bother documenting these methods in the first place, but here's the argument list as well:
想知道为什么我首先要记录这些方法,但这里还有参数列表:
/**
* 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
*/