PHPExcel:读取所有值(日期,时间,数字)作为字符串


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

我遇到日期和时间的问题。我想让他们读就像他们出现在excel工作簿。

所以,我相信如果我使用toArray()获得工作表的所有单元格,那么我应该简单地做一些事情(一些格式转换),将所有单元格映射为字符串,日期,时间等。

或者可能有像load这样的函数,它将工作簿中的所有数据加载为字符串,而不需要任何格式化或其他复杂的东西。

toArray()支持以下参数:

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

toArray(NULL,TRUE,TRUE);

将返回工作表中的所有单元格值(计算和格式化),与Excel本身完全相同。

因此日期将返回为(例如)21-Dec-2011 07:30而不是47239.318(取决于单元格的格式掩码)。其他数值单元格可以返回为21,357.00(取决于该单元格的格式屏蔽),因此它是一把双刃剑。