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

那年仲夏 提交于 2019-12-18 04:03:22

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/8583915/phpexcel-read-all-values-date-time-numbers-as-strings

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!