在phpexcel中为列添加标题时,会隐藏结果的第一行


$users = $query->result_array();
$this->excel->getActiveSheet()->SetCellValue('A1', 'Name');
$this->excel->getActiveSheet()->SetCellValue('B1', 'Email');
$this->excel->getActiveSheet()->SetCellValue('C1', 'Gender');
$this->excel->getActiveSheet()->SetCellValue('D1', 'DOB');
$this->excel->getActiveSheet()->SetCellValue('E1', 'Class');
$this->excel->getActiveSheet()->SetCellValue('F1', 'School Name');
$this->excel->getActiveSheet()->SetCellValue('G1', 'City');
$this->excel->getActiveSheet()->SetCellValue('H1', 'State');
$this->excel->getActiveSheet()->SetCellValue('I1', 'Primary Contact');
$this->excel->getActiveSheet()->SetCellValue('J1', 'Secondary Contact');
$this->excel->getActiveSheet()->SetCellValue('K1', 'Teacher Contact');
$this->excel->getActiveSheet()->fromArray($users);

$filename = 'userlist.xls'; //save our workbook as this file name
header('Content-Type: application/vnd.ms-excel'); //mime type
header('Content-Disposition: attachment;filename="' . $filename . '"'); //tell browser what's the file name
header('Cache-Control: max-age=0'); //no cache

$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');

$objWriter->save('php://output');

我正在CodeIgniter上处理这些代码。它很好用,但唯一我不能解决的问题它隐藏数据库输出的第一行。如何从CCD_ 1开始转换数据库结果。

您可以在没有的单元格上引用无起始单元格

$current_cell = 2;
foreach ($cell_val as $cell) {
$objPHPExcel->getActiveSheet()->fromArray($cell, null, 'A'.$current_cell);
$current_cell++;
}

相关内容

  • 没有找到相关文章

最新更新