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

时间:2011-12-21 00:57:33

标签: php phpexcel

我正面临着日期和时间的问题。我希望它们能够像excel工作簿中那样被阅读。

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

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

1 个答案:

答案 0 :(得分:13)

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本身中显示的完全相同。

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