2014-01-27 84 views
0

我試圖設置年齡計算公式在PHPExcel給予致命錯誤

公式

=DATEDIF(J2,DATE(2014,3,31),"Y")&" Years, "&DATEDIF(J2,DATE(2014,3,31),"YM")&" Months, "&DATEDIF(J2,DATE(2014,3,31),"MD")&" Days"

其中在J列取決於DOB 1500列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")'); 
} 

但我得到這個錯誤 -

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 -&gt; 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-&gt;getCalculatedValue() 
#1 C:\xampp\htdocs\manazeschool\software\office_admin\exam_excel\Classes\PHPExcel\Writer\Excel2007\Worksheet.php(1025): PHPExcel_Writer_Excel2007_Worksheet-&gt;_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-&gt;_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

經過漫長等待答覆,我開始探索解決方案,並最終這是解決我的問題代碼

$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")'); 
} 

計算器的每個用戶都沒有專家,我們來這裏是爲了指導專家。我等了12小時的任何建議或幫助,但沒有人出現。這是可悲的。