3
でExcelファイルを生成するデータベースからのデータをExcelファイルを生成するために、ローカルホストで正常に動作しますが、サーバーをホストに、それは空白のExcelファイルを生成私のコードです:phpexcelライブラリは、ローカルホスト上で正常に動作しますが、ブランクはここでサーバー
// Starting the PHPExcel library
$this->load->library('PHPExcel');
//$this->load->library('PHPExcel/IOFactory');
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setTitle("export")->setDescription("none");
$objPHPExcel->setActiveSheetIndex(0);
// Field names in the first row
$fields = $query->list_fields();
$col = 0;
foreach ($fields as $field)
{
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, 1, $field);
$col++;
}
//format the column sizes
$sheet = $objPHPExcel->getActiveSheet();
$cellIterator = $sheet->getRowIterator()->current()->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(true);
/** @var PHPExcel_Cell $cell */
foreach($cellIterator as $cell) {
$sheet->getColumnDimension($cell->getColumn())->setAutoSize(true);
}
//var_dump($query->result());
//die;
// Fetching the table data
$row = 2;
foreach($query->result() as $data)
{
$col = 0;
foreach($fields as $field)
{
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $data->$field);
$col++;
}
$row++;
}
$objPHPExcel->setActiveSheetIndex(0);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="01simple.xlsx"');
header('Cache-Control: max-age=0');
ob_clean();
$objWriter->save('php://output');
を
ローカルサーバーに適切な依存関係(モジュール)がインストールされていて、ホストされているサーバーに存在しない可能性があります。それは最初に調べるべきことです。 – TimBrownlaw
にもこの問題がありました。解決策を見つけることができませんでした:-( –