Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPExcel: Read all values (date, time, numbers) as strings

Tags:

php

phpexcel

I am facing issues with dates and time. I want them to be read just like they appear in the excel workbook.

So, I believe if I get all cells of the sheet using toArray(), then I should simply do something (some format conversion) that will map all cells as strings, dates, times etc.

OR may be there is function like load, which load all data in the workbook as string without any formating or other complex stuff.

like image 612
WebSoft Avatar asked Dec 21 '11 00:12

WebSoft


1 Answers

toArray() supports the following arguments:

/**
 * @param  mixed    $nullValue          Value returned in the array entry if a cell doesn't 
 *                                      exist
 * @param  boolean  $calculateFormulas  Should formulas be calculated?
 * @param  boolean  $formatData         Should formatting be applied to cell values?
 * @param  boolean  $returnCellRef      False - Return a simple array of rows and 
 *                                      columns indexed by number counting from zero
 *                                      True - Return rows and columns indexed by their 
 *                                      actual row and column IDs
 */

so

toArray(NULL,TRUE,TRUE);

will return all the cell values in the worksheet (calculated and formatted) exactly as they appear in Excel itself.

So dates will be returned as (for example) 21-Dec-2011 07:30 rather than 47239.318 (depending on the format mask for the cell). Other numeric cells could be returned as 21,357.00 (depending on the format masking for that cell) so it is a two-edged sword.

like image 179
Mark Baker Avatar answered Oct 18 '22 16:10

Mark Baker