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

Adi*_*M P 33 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搜索技巧......

Mar*_*ker 72

$objPHPExcel->getActiveSheet()->fromArray($testArray, NULL, 'A1');
Run Code Online (Sandbox Code Playgroud)

它被用在许多例子中

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
 */
Run Code Online (Sandbox Code Playgroud)

  • 它确实支持2d阵列:1d阵列被视为单行,2-d阵列被视为一系列单元; 但它们必须是常规数组(即每行中相同数量的列)... 33chartcreate和10autofilter选择示例都使用2d数组 (8认同)