PHPExcel中是否有一个方法可以将PHP数组直接写入一行?

时间:2012-12-13 21:42:12

标签: php phpexcel

据我所知,我需要编写一个循环,我在其中使用SetCellValue('cell_name', 'value');但PHPExcel中是否有一个方法只接受一个数组并将其写入Excel工作表行?

类似的东西:

$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

我在附带的文档中找不到类似的内容,但这可能只是糟糕的PDF搜索技巧......

1 个答案:

答案 0 :(得分:72)

$objPHPExcel->getActiveSheet()->fromArray($testArray, NULL, 'A1');

它用于许多例子

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
 */