drvpvmz16241016 2018-07-13 08:59
浏览 291

在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');

I'm working this code on CodeIgniter. it works fine but the only thing I am not able to fix it hides the first row of database output. how to shift database result to start from A2.

  • 写回答

1条回答 默认 最新

  • dongwen4487 2018-07-13 09:02
    关注

    you may reference cell no starting on cell no

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

报告相同问题?

悬赏问题

  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了