我有一个HTML表格,我在系统上显示有关用户的行。这些行也会写入可下载的Excel电子表格中。完全相同的信息将发送到电子表格:
$row=2;
$odd='';
foreach($feedata as $user_data){
$col=1;
$name=$user_data['first_name'].' '.$user_data['surname'];
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col++, $row, $name);
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col++, $row,$user_data['email']);
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col++, $row, $user_data['phone']);
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col++, $row, $user_data['regdate']);
$odd=($odd=='even')?'odd':'even';
echo '
<tr class="<?php echo $odd;?>">
<td>
<a href="'.$URI.'?userid='.$user_data['id'].'">
'.$name.'
</a>
</td>
<td>
<a href="#self" onclick="showmailform(\''.$name.'\',\''.$user_data['email'].'\');return false;">
'.$user_data['email'].'
</a>
</td>
<td>
'.$user_data['phone'].'
</td>
<td>
'.$user_data['regdate'].'
</td>
';
for($i=2015;$i<$subscriptions;$i++){
$amnt=$user_data[$i];
$sp_amnt='';
if(!$amnt){
$amnt=' ';
}
else{
$sp_amnt=$amnt;
if(is_numeric($amnt)){
$amnt='£'.$amnt;
}
}
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col++, $row, $sp_amnt);
$cellname=chrono_char($col).$row;
# $objPHPExcel-getStyle($cellname)->getNumberFormat()->setFormatCode($currencyFormat);
echo '
<td>'.$amnt.'
</td>';
}
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col++, $row, $user_data['paid_upto']);
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col++, $row, $user_data['paymentEA']);
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col++, $row, $user_data['paymentHWSA']);
$row++;
echo '
<td>'.$user_data['paid_upto'].'</td>
<td>'.$user_data['paymentEA'].'</td>
<td>'.$user_data['paymentHWSA'].'</td>
</tr>
';
}
echo '</table>';
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
echo 'Download excel version of the report <a href="'.plugins_url('chrono_reg/tmp/').'subscriptions.xls">HERE.</a>';
renderEmailForm();
$excelfilename=$pldir.'tmp/subscriptions.xls';
$objWriter->save($excelfilename);
chmod($excelfilename, 0664);
chown($excelfilename,'www-data');
HTML表格正确显示,但电子表格缺少行。
HTML表:
Paula Ilott | Ptxxxxx@example.co.uk | 087xxxxxx | 04-04-2016 | | | | | | | | |
---------------------------------------------------------------
Damian Jesson | dxxxx@gmail.co.uk | 01708 xxxx xxx | 23-05-2016 | | | | | | | | |
---------------------------------------------------------------
Nicolette Middleton | nxxxxx@gmail.com | +44xxxxxxxxxxx | 11-02-2016 | | £53.00 | | | | | 31-03-2016 | 31-03-2017 |
电子表格表:
Paula Ilott | Ptxxxxx@example.co.uk | 087xxxxxx | 04-04-2016 | | | | | | | | |
---------------------------------------------------------------
Nicolette Middleton | nxxxxx@gmail.com | +44xxxxxxxxx | 11-02-2016 | | 0 | | | | | 31-03-2016 | 31-03-2017 |
我完全不知所措。
作为一个单独的问题,付款金额始终是&#39; 0&#39;在电子表格中(上例中的53.00),但是一旦我解决了这个差异,我就会研究它。
答案 0 :(得分:0)
我已经重写了代码,现在似乎可以正常工作。
老实说我真的不知道出了什么问题。
上面发布的代码并不是我所拥有的代码,因为我进行了一些编辑以使问题更加清晰。它最初主要是HTML格式,&lt; ?php echo $ name;?&gt; 而不是使用 echo'&lt; TD&GT;&LT '$名称。'; / td&gt;'; 正如我上面发布的那样。
这是原始代码的样子:
$row=2;
$odd='';
foreach($feedata as $user_data){
$col=1;
$name=$user_data['first_name'].' '.$user_data['surname'];
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col++, $row, $name);
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col++, $row,$user_data['email']);
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col++, $row, $user_data['phone']);
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col++, $row, $user_data['regdate']);
$odd=($odd=='even')?'odd':'even';?>
<tr class="<?php echo $odd;?>">
<td>
<a href="<?php echo $URI.'?userid='.$user_data['id'];?>">
<?php echo $name;?>
</a>
</td>
<td>
<a href="#self" onclick="showmailform('<?php echo $name."','".$user_data['email'];?>');return false;">
<?php echo $user_data['email'];?>
</a>
</td>
<td>
<?php echo $user_data['phone'];?>
</td>
<td>
<?php echo $user_data['regdate'];?>
</td>
<?php
for($i=2015;$i<$subscriptions;$i++){
$amnt=$user_data[$i];
$sp_amnt='';
if(!$amnt){
$amnt=' ';
}
else{
$sp_amnt=$amnt;
if(is_numeric($amnt)){
$amnt='£'.$amnt;
}
}
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col++, $row, $sp_amnt);
$cellname=chrono_char($col).$row;
# $objPHPExcel-getStyle($cellname)->getNumberFormat()->setFormatCode($currencyFormat);
echo '
<td>'.$amnt.'
</td>';
}
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col++, $row, $user_data['paid_upto']);
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col++, $row, $user_data['paymentEA']);
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col++, $row, $user_data['paymentHWSA']);
$row++;?>
<td><?php echo $user_data['paid_upto'];?></td>
<td><?php echo $user_data['paymentEA'];?></td>
<td><?php echo $user_data['paymentHWSA'];?></td>
</tr><?php
}
echo '</table>';
对不起,如果我浪费了任何人的时间;我真的应该在发布之前测试修改后的代码。