嗨我刚接触phpExcel并尝试将查询结果导出到excel。我当前的单元格名称类似于ID,Person,Subject1,Subject2(A1,B1,C1,D1)。 这里每个科目都包括标记和等级,我想显示标记和等级。对于那些科目,优秀成绩。这就是细胞分裂从C2开始。 有什么想法吗?
$this->excel->getActiveSheet()->setCellValue('A1', 'ID');
$this->excel->getActiveSheet()->setCellValue('B1', 'Person');
$this->excel->getActiveSheet()->setCellValue('C1', 'Subject1');
$this->excel->getActiveSheet()->setCellValue('D1', 'Subject2');
$row=2;
foreach($data->result() as $row);
{
$this->excel->getActiveSheet()->setCellValue('A'.$row, $row->id);
$this->excel->getActiveSheet()->setCellValue('B'.$row, $row->name);
/*
??
*/
$row++;
}
答案 0 :(得分:1)
Change your $row variable
$this->excel->getActiveSheet()->setCellValue('A1', 'ID');
$this->excel->getActiveSheet()->setCellValue('B1', 'Person');
$this->excel->getActiveSheet()->setCellValue('C1', 'Subject1');
$this->excel->getActiveSheet()->setCellValue('D1', 'Subject2');
$count=2;
foreach($data->result() as $row);
{
$this->excel->getActiveSheet()->setCellValue('A'.$count, $row->id);
$this->excel->getActiveSheet()->setCellValue('B'.$count, $row->name);
/*
??
*/
$count++;
}