Reputation: 1427
Below the sample codes. It's may help you.. When i'm change the row number(1) into 5 then seven rows are empty in excel sheet.(LOCATION : setCellValueByColumnAndRow($col, 1, $field);)
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setTitle("export")->setDescription("none");
$objPHPExcel->setActiveSheetIndex(0);
$fields = array('ram','one','two');
$col = 0;
foreach ($fields as $field)
{
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, 1, $field);
$col++;
}
header('Content-Type: text/csv');
header('Content-Disposition: attachment;filename="Export.csv"');
header('Cache-Control: max-age=0');
$objWriter->save('php://output');
Upvotes: 2
Views: 1375
Reputation: 212412
You're defining $field
but foreach references $fields
.... that s
makes a lot of difference
$field = array('ram','one','two');
and
foreach ($fields as $field)
Try defining your array with the correct variable name
$fields = array('ram','one','two');
Upvotes: 1
Reputation: 51
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setTitle("export")->setDescription("none");
$objPHPExcel->setActiveSheetIndex(0);
$field = array('ram','one','two');
$col = 0;
foreach ($fields as $field)
{
if(empty($field)){
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, 1, $field);
$col++;
}
}
header('Content-Type: text/csv');
header('Content-Disposition: attachment;filename="Export.csv"');
header('Cache-Control: max-age=0');
$objWriter->save('php://output');
Upvotes: 1