$sheet = $this->phpExcel->getActiveSheet();
// header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
//header('Content-Disposition: attachment;filename="your_name.xlsx"');
//header('Cache-Control: max-age=0');
$sheet->setCellValue('A1', 'keterangan');
$sheet->setCellValue('B1', '8');
$sheet->setCellValue('C1', '9');
$sheet->setCellValue('D1', '10');
$sheet->setCellValue('E1', '11');
$sheet->setCellValue('F1', '12');
$sheet->setCellValue('G1', '13');
$sheet->setCellValue('H1', '14');
$sheet->setCellValue('I1', '15');
$sheet->setCellValue('J1', '16');
$sheet->setCellValue('K1', '17');
$sheet->setCellValue('L1', '18');
$sheet->setCellValue('M1', '19');
$sheet->setCellValue('N1', '20');
$sheet->setCellValue('O1', '21');
$sheet->setCellValue('P1', '22');
$sheet->setCellValue('Q1', '23');
$sheet->setCellValue('R1', '24');
$sheet->setCellValue('S1', '1');
$sheet->setCellValue('T1', '2');
$sheet->setCellValue('U1', '3');
$sheet->setCellValue('V1', '4');
$sheet->setCellValue('W1', '5');
$sheet->setCellValue('X1', '7');
$sheet->setCellValue('Y1', '6');
// $sheet->setCellValue('G1', 'Saldo');
$i = 2;
foreach ($data as $idx) {
$sheet->setCellValue('A' . $i, $idx->name);
$sheet->setCellValue('B' . $i, $idx->kiln_detail);
//$sheet->setCellValue('C' . $i,$idx->);
//$col='A';
}
$objWriter = PHPExcel_IOFactory::createWriter($this->phpExcel, 'Excel2007');
$objWriter->save('a.xlsx');
}
结果$ data这是
Array
(
[0] => stdClass Object
(
[name] => BINGKAI
[kiln_detail] => 1
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
[14] => 4
[15] =>
[16] =>
[17] =>
[18] =>
[19] =>
[20] =>
[21] =>
[22] =>
[23] =>
[24] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[JML_JAM] => 6
)
[1] => stdClass Object
(
[name] => BISUL / BENTOL
[kiln_detail] => 1
[8] =>
[9] => 3
[10] => 4
[11] =>
[12] => 4
[13] =>
[14] => 3
[15] => 3
[16] =>
[17] =>
[18] =>
[19] =>
[20] =>
[21] =>
[22] =>
[23] =>
[24] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[JML_JAM] => 6
)