我正在尝试设置年龄计算公式
列L中的= DATEDIF(J2,DATE(2014,3,31),“Y”)&“Years”,& DATEDIF(J2,DATE(2014,3,31),“YM”)&“Months , “&安培; DATEDIF(J2,DATE(2014,3,31),” MD “)及”天“
依赖于列J中的DOB 1500列,我的代码就像这样
for($i=2;$i<=1500;$i++){
$objPHPExcel->getActiveSheet()->setCellValue('L'.$i.',=DATEDIF(J'.$i.',DATE(31-03-2014),"Y") & DATEDIF(J'.$i.',DATE(31-03-2014),"YM") &DATEDIF(J'.$i.',DATE(31-03-2014),"MD")');
}
但是我收到了这个错误 -
致命错误:带有消息的未捕获异常'PHPExcel_Exception' '细胞坐标不能是一系列细胞。'在 C:\ XAMPP \ htdocs中\ manazeschool \ SOFTWARE \ office_admin \ exam_excel \类\ PHPExcel \ Worksheet.php:1127 堆栈跟踪:#0 C:\ XAMPP \ htdocs中\ manazeschool \ SOFTWARE \ office_admin \ exam_excel \类\ PHPExcel \ Worksheet.php(1042): PHPExcel_Worksheet-&gt; getCell('L2,= DATEDIF(J2,...')#1 C:\ XAMPP \ htdocs中\ manazeschool \ SOFTWARE \ office_admin \ exam_excel \ excel_export.php(83): PHPExcel_Worksheet-&gt; setCellValue('L2,= DATEDIF(J2,...')#2 {main} 投入 C:\ XAMPP \ htdocs中\ manazeschool \ SOFTWARE \ office_admin \ exam_excel \类\ PHPExcel \ Worksheet.php 在1127号线上
我做错了什么,请指导我。
我在 setCellValue('L'。$ i。',= ... 更改了错误的公式,现在它是 setCellValue('L'。$ i,'= ..
for($i=2;$i<=1500;$i++){ $objPHPExcel->getActiveSheet()->setCellValue('L'.$i,'=DATEDIF(J'.$i.',DATE(31-03-2014),"Y") &DATEDIF(J'.$i.',DATE(31-03-2014),"YM") &DATEDIF(J'.$i.',DATE(31-03-2014),"MD")');
}
文件已下载但文件格式文件的文件扩展名错误无法打开。
我在记事本中打开了excel文件,看到了错误,我发现了这条消息
<br/>
<b>Fatal error</b>: Uncaught exception 'PHPExcel_Calculation_Exception' with message 'Registration Format!L2 -> Formula Error: Wrong number of arguments for DATE() function: 1 given, 3 expected' in C:\xampp\htdocs\manazeschool\software\office_admin\exam_excel\Classes\PHPExcel\Cell.php:298
Stack trace:
#0 C:\xampp\htdocs\manazeschool\software\office_admin\exam_excel\Classes\PHPExcel\Writer\Excel2007\Worksheet.php(1078): PHPExcel_Cell->getCalculatedValue()
#1 C:\xampp\htdocs\manazeschool\software\office_admin\exam_excel\Classes\PHPExcel\Writer\Excel2007\Worksheet.php(1025): PHPExcel_Writer_Excel2007_Worksheet->_writeCell(Object(PHPExcel_Shared_XMLWriter), Object(PHPExcel_Worksheet), 'L2', Array, Array)
#2 C:\xampp\htdocs\manazeschool\software\office_admin\exam_excel\Classes\PHPExcel\Writer\Excel2007\Worksheet.php(83): PHPExcel_Writer_Excel2007_Worksheet->_writeSheetData(Object(PHPExcel_Shared_XMLWriter), Object(PHPExcel_Worksheet), Array)
#3 C:\xampp\htdocs\manazeschool\software\office_admin\exam_excel\Classes\PHPExcel\Writer\Exce in <b>C:\xampp\htdocs\manazeschool\software\office_admin\exam_excel\Classes\PHPExcel\Cell.php</b> on line <b>298</b><br />
答案 0 :(得分:0)
经过漫长的等待回复,我开始探索解决方案,最后这是解决我问题的代码
$date = date('2014,03,31');
for($i=2;$i<=1500;$i++){
$objPHPExcel->getActiveSheet()->setCellValue('L'.$i,'=DATEDIF(J'.$i.',DATE('.$date.'),"Y") &DATEDIF(J'.$i.',DATE('.$date.'),"YM") &DATEDIF(J'.$i.',DATE('.$date.'),"MD")');
}
stackoverflow的每个用户都不是专家我们来这里寻求专家的指导。我等了12个小时的任何建议或帮助,但没有人出现。很遗憾。