如何使用Codeigniter在PHPExcel中设置循环编号

时间:2016-06-16 08:31:16

标签: php codeigniter phpexcel

Image

如何在phpexcel中循环编号?

我使用codeigniter。

$rs = $this->db->get('inventory_barang');
$exceldata="";
foreach ($rs->result_array() as $row){
$exceldata[] = $row;
}

//How should i do for looping 
$this->excel->getActiveSheet()->fromArray('I want number to be looping for column A from A4', null, 'A4');

// read data to active sheet
$this->excel->getActiveSheet()->fromArray($exceldata, null, 'B4');

1 个答案:

答案 0 :(得分:1)

您可以为数组添加数字:

$rs = $this->db->get('inventory_barang');
$exceldata = [];
foreach ($rs->result_array() as $key=>$row){
    $exceldata[] = array_merge([$key], $row);
}
$this->excel->getActiveSheet()->fromArray($exceldata, null, 'A4');