我試圖設置年齡計算公式在PHPExcel給予致命錯誤
公式其中在J列取決於DOB 1500列L列=DATEDIF(J2,DATE(2014,3,31),"Y")&" Years, "&DATEDIF(J2,DATE(2014,3,31),"YM")&" Months, "&DATEDIF(J2,DATE(2014,3,31),"MD")&" Days"
,我的代碼是這樣的
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")');
}
但我得到這個錯誤 -
Fatal error: Uncaught exception 'PHPExcel_Exception' with message 'Cell coordinate can not be a range of cells.' in C:\xampp\htdocs\manazeschool\software\office_admin\exam_excel\Classes\PHPExcel\Worksheet.php:1127 Stack trace: #0 C:\xampp\htdocs\manazeschool\software\office_admin\exam_excel\Classes\PHPExcel\Worksheet.php(1042): PHPExcel_Worksheet->getCell('L2,=DATEDIF(J2,...') #1 C:\xampp\htdocs\manazeschool\software\office_admin\exam_excel\excel_export.php(83): PHPExcel_Worksheet->setCellValue('L2,=DATEDIF(J2,...') #2 {main} thrown in C:\xampp\htdocs\manazeschool\software\office_admin\exam_excel\Classes\PHPExcel\Worksheet.php on line 1127
我在做什麼錯誤,請指導我。
我在setCellValue( 'L' 改變錯誤的公式。$ I '= ...現在是setCellValue(' L '$我,'= ...
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 />