请教各位,我在使用phpexcel读取excel文件,当excel单元格的类型为“日期”时,phpexcel读出来的是一个类似21311的数,这个问题怎么解决?
另外phpexcel怎么判断excel单元格的数据是整形、字符型还是日期?谢谢大家!
<?
require_once 'PHPExcel-1.7.3/PHPExcel-1.7.3/PHPExcel.php';//包含类
require_once 'PHPExcel-1.7.3/PHPExcel-1.7.3/PHPExcel/IOFactory.php'; $objReader = PHPExcel_IOFactory::createReader('Excel5');
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load("excel.xls");
$objWorksheet = $objPHPExcel->getActiveSheet();
$highestRow = $objWorksheet->getHighestRow(); //
$highestColumn = $objWorksheet->getHighestColumn(); //
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); // echo '<table>' . "\n";
//for ($row = 2; $row <= $highestRow; ++$row) {
echo '<tr>' . "\n";
for ($col = 0; $col <= $highestColumnIndex; ++$col) {
echo '<td>[' . $objWorksheet->getCellByColumnAndRow($col, 3)->getValue() . ']</td>' . "\n";
if($col==7)//得到日期结果
{
echo $objWorksheet->getCellByColumnAndRow($col, 3)->getValue();
}
}
echo '</tr>' . "\n";
//}
echo '</table>' . "\n";
?>
另外phpexcel怎么判断excel单元格的数据是整形、字符型还是日期?谢谢大家!
<?
require_once 'PHPExcel-1.7.3/PHPExcel-1.7.3/PHPExcel.php';//包含类
require_once 'PHPExcel-1.7.3/PHPExcel-1.7.3/PHPExcel/IOFactory.php'; $objReader = PHPExcel_IOFactory::createReader('Excel5');
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load("excel.xls");
$objWorksheet = $objPHPExcel->getActiveSheet();
$highestRow = $objWorksheet->getHighestRow(); //
$highestColumn = $objWorksheet->getHighestColumn(); //
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); // echo '<table>' . "\n";
//for ($row = 2; $row <= $highestRow; ++$row) {
echo '<tr>' . "\n";
for ($col = 0; $col <= $highestColumnIndex; ++$col) {
echo '<td>[' . $objWorksheet->getCellByColumnAndRow($col, 3)->getValue() . ']</td>' . "\n";
if($col==7)//得到日期结果
{
echo $objWorksheet->getCellByColumnAndRow($col, 3)->getValue();
}
}
echo '</tr>' . "\n";
//}
echo '</table>' . "\n";
?>
解决方案 »
- 会XSL的进..用的MYSQL数据库~!在线等!!!
- 将脚本嵌入到网页中的模式,是最终会被淘汰吗?(php就是这样呀)
- 悻福ル蒤嘫 这个名字 通过 $_POST['nickname'] 抓到后变成了 悻福ル蒤\嘫 怎么回事呢?
- 禁用cookie标签
- 2003装好php4.3.9和mysql 4后,不能调用数据库,有谁知道原因,请指教。
- PHP中怎样下载EXCEL文件?
- 深圳做 php 开发的能否留下一个联系方式
- 开始整理以前的帖子,如果你发现你的专家分和可用分大副上升,或参与分大副下降,请不要惊讶 (zxyufan)
- session在windows2000 server中出错
- 初学php想找份实习工作
- 这段JS在火狐下报错求高手
- 是不是用PHP写个论坛很难?怎么很多网站都用一些论坛产品呢?
date('yyyy-mm-dd', $date); 这样转换的话是错误的
//excel日期转换函数
function excelTime($days, $time=false){
if(is_numeric($days)){
//based on 1900-1-1
$jd = GregorianToJD(1, 1, 1970);
$gregorian = JDToGregorian($jd+intval($days)-25569);
$myDate = explode('/',$gregorian);
$myDateStr = str_pad($myDate[2],4,'0', STR_PAD_LEFT)
."-".str_pad($myDate[0],2,'0', STR_PAD_LEFT)
."-".str_pad($myDate[1],2,'0', STR_PAD_LEFT)
.($time?" 00:00:00":'');
return $myDateStr;
}
return $days;
}