Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a method in PHPExcel to write a PHP array directly into a row?

Tags:

php

phpexcel

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?

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...

like image 800
Aditya M P Avatar asked Dec 13 '12 21:12

Aditya M P


People also ask

Is PHPExcel deprecated?

PHP Excel was officially deprecated in 2017 and permanently archived in 2019. PHP Excel has not be maintained for years and must not be used anymore. All users must migrate to its direct successor PhpSpreadsheet, or another alternative.

How to get cell value in PHPExcel?

function toNumber($dest) { if ($dest) return ord(strtolower($dest)) - 96; else return 0; } function myFunction($s,$x,$y){ $x = toNumber($x); return $s->getCellByColumnAndRow($x, $y)->getFormattedValue(); } $objReader = PHPExcel_IOFactory::createReader($inputFileType); $objPHPExcel = $objReader->load($inputFileName); $ ...

How to get cell value in PhpSpreadsheet?

To retrieve the value of a cell, the cell should first be retrieved from the worksheet using the getCell() method. A cell's value can be read using the getValue() method. // Get the value from cell A1 $cellValue = $spreadsheet->getActiveSheet()->getCell('A1')->getValue();


1 Answers

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

It's used in a number of the examples

Arguments as described in the API docs

/**  * 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  */ 
like image 198
Mark Baker Avatar answered Sep 23 '22 08:09

Mark Baker