phpexcel读取excel 时间
//读取excel文件
$info = pathinfo ( $path );
$ext = $info ['extension'];
$excelreader = null;
if ( $ext == 'xls' )
$excelreader = new phpexcel_reader_excel5();
else
$excelreader = new phpexcel_reader_excel2007();
$phpexcelinstance = $excelreader->load($path);
$sheet = $phpexcelinstance -> getsheet ( 0 );
// 读取第一個工作表
$highestrow = $sheet->gethighestrow(); // 取得总行数
$highestcolumm = $sheet->gethighestcolumn(); // 取得总列数
/** 循环读取每个单元格的数据 **/
$arr = array ();
for ( $row = 2 ; $row <= $highestrow ; $row ++ )
{ // 行数是以第2行开始
$cell = $sheet->getcellbycolumnandrow(0, $row);
$value = $cell->getvalue();
if (empty($create_date) || !isset($create_date))
{
$create_date = date("y-m-d");
}
else
{
if ($cell->getdatatype()==phpexcel_cell_datatype::type_numeric)
{
$cellstyleformat=$cell->getstyle()->getnumberformat(); //获取cell类型
$formatcode=$cellstyleformat->getformatcode(); //获取cell格式代码,时间格式为mm-dd-yy
if (preg_match('/^(/[/$[a-z]*-[0-9a-f]*/])*[hmsdy]/i', $formatcode))
{
$create_date = gmdate("y-m-d", phpexcel_shared_date::exceltophp($value));
}else{
$create_date = phpexcel_style_numberformat::toformattedstring($value,$formatcode);
}
}
else
{
$create_date = date("y-m-d");
}
}
//读取excel文件
$info = pathinfo ( $path );
$ext = $info ['extension'];
$excelreader = null;
if ( $ext == 'xls' )
$excelreader = new phpexcel_reader_excel5();
else
$excelreader = new phpexcel_reader_excel2007();
$phpexcelinstance = $excelreader->load($path);
$sheet = $phpexcelinstance -> getsheet ( 0 );
// 读取第一個工作表
$highestrow = $sheet->gethighestrow(); // 取得总行数
$highestcolumm = $sheet->gethighestcolumn(); // 取得总列数
/** 循环读取每个单元格的数据 **/
$arr = array ();
for ( $row = 2 ; $row <= $highestrow ; $row ++ )
{ // 行数是以第2行开始
$cell = $sheet->getcellbycolumnandrow(0, $row);
$value = $cell->getvalue();
if (empty($create_date) || !isset($create_date))
{
$create_date = date("y-m-d");
}
else
{
if ($cell->getdatatype()==phpexcel_cell_datatype::type_numeric)
{
$cellstyleformat=$cell->getstyle()->getnumberformat(); //获取cell类型
$formatcode=$cellstyleformat->getformatcode(); //获取cell格式代码,时间格式为mm-dd-yy
if (preg_match('/^(/[/$[a-z]*-[0-9a-f]*/])*[hmsdy]/i', $formatcode))
{
$create_date = gmdate("y-m-d", phpexcel_shared_date::exceltophp($value));
}else{
$create_date = phpexcel_style_numberformat::toformattedstring($value,$formatcode);
}
}
else
{
$create_date = date("y-m-d");
}
}
相关文章:
php导出excel时科学计数法的处理方法
php原生导出excel文件的两种方法
通过php实现获取excel文档内容的代码实例
以上就是详细介绍phpexcel读取excel时间的示例代码的详细内容。