php PHPExcel中是否有将PHP数组直接写入一行的方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13868972/
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
Is there a method in PHPExcel to write a PHP array directly into a row?
提问by Aditya M P
I understand that I'll need to write a loop inside which I use SetCellValue('cell_name', 'value'); but is there a method in PHPExcel that just accepts a single array and writes that into an Excel sheet row?
我知道我需要编写一个循环来使用SetCellValue('cell_name', 'value');但是 PHPExcel 中是否有一种方法只接受单个数组并将其写入 Excel 工作表行?
Something like:
就像是:
$testArray = array('testcelltext1', 'testcelltext2', testcelltext3');
PHPExcel::writeArraytoRow($testArray);
//do the other PHPExcel stuff to actually write the file
.
.
.
// outputs an excel file in which the PHP array was written to the first row
I could not find something like that in the included documentation, but that might just be bad PDF search skills...
我在包含的文档中找不到类似的东西,但这可能只是糟糕的 PDF 搜索技巧......
回答by Mark Baker
$objPHPExcel->getActiveSheet()->fromArray($testArray, NULL, 'A1');
It's used in a number of the examples
它在许多示例中使用
Arguments as described in the API docs
API 文档中描述的参数
/**
* Fill worksheet from values in array
*
* @param array $source Source array
* @param mixed $nullValue Value in source array that stands for blank cell
* @param string $startCell Insert array starting from this cell address as the top left coordinate
* @param boolean $strictNullComparison Apply strict comparison when testing for null values in the array
* @throws Exception
* @return PHPExcel_Worksheet
*/

