PHPExcel中是否有将PHP数组直接写入行的方法?

2022-08-30 13:36:32

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

像这样:

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

答案 2

推荐