PHPexcel从Mysql中添加行

时间:2014-01-21 12:48:25

标签: php mysql phpexcel

我有一个发布到mysql的表单:

enter image description here

前两个条目(ID和用户)需要进入一次特定的Cell:

$objPHPExcel->getActiveSheet()->SetCellValue('A1', $row['ID']);
$objPHPExcel->getActiveSheet()->SetCellValue('C1', $row['User']);

其他人(日期,单位和数字)需要从左到右发布到该行。

像这样:

enter image description here

1 个答案:

答案 0 :(得分:1)

//some code to get the data from mysql

//teller to know where to start in sql
$teller = 5;
foreach($yourarray as $row){
    $objPHPExcel->getActiveSheet()->SetCellValue('A' . $teller, $row['ID']);
    $objPHPExcel->getActiveSheet()->SetCellValue('B' . $teller, $row['User']); 
    $objPHPExcel->getActiveSheet()->SetCellValue('C' . $teller, $row['Date']); 
    //D - Z?
    $teller++;
}

这就是你想要的?