我想将数据导出到 CI 中的 excel。但我有问题Undefined index: wc_order_id如果我print_r(array_values($data)); exit;该值是正确的,只是我无法导出到 Excel。这是我的控制器:public function createExcel($awals, $akhirs, $status) { $fileName = 'Reservation.xlsx'; $data['data'] = $this->M_reservation->all_order($awals, $akhirs, $status) ; $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $total = 0; $sheet->setCellValue('A1', 'No'); $sheet->setCellValue('B1', 'Booking ID'); $sheet->setCellValue('C1', 'Order Date'); $sheet->setCellValue('D1', 'Client Name'); $sheet->setCellValue('E1', 'Client Email'); $sheet->setCellValue('F1', 'Phone'); $sheet->setCellValue('G1', 'Inclution'); $sheet->setCellValue('H1', 'Room name'); $sheet->setCellValue('I1', 'Bed Order'); $sheet->setCellValue('J1', 'Status'); $sheet->setCellValue('K1', 'Total Order'); $rows = 2; $no = 1; $total=0; foreach ($data as $val){ $sheet->setCellValue('A' . $rows, $no++); $sheet->setCellValue('B' . $rows, $val['wc_order_id']); $sheet->setCellValue('C' . $rows, $val['post_date']); $sheet->setCellValue('D' . $rows, $val['display_name']); $sheet->setCellValue('E' . $rows, $val['user_email']); $sheet->setCellValue('F' . $rows, $val['meta_value']); $sheet->setCellValue('G' . $rows, $val['display_name']); $sheet->setCellValue('H' . $rows, $val['post_title']); $sheet->setCellValue('I' . $rows, $val['room_num_search']); $sheet->setCellValue('J' . $rows, $val['status']); $sheet->setCellValue('K' . $rows, $val['total_order']); $total = $total+$val['total_order']; $rows++; }
1 回答
慕哥6287543
TA贡献1831条经验 获得超10个赞
您正在存储值,$data['data']这意味着变量$data具有存储结果数组的key名称。data所以,你可以
依次通过$data['data']
$data['data'] = $this->M_reservation->all_order($awals, $akhirs, $status) ; // no change
// ...
// ...
foreach($data['data'] as $val){ // change here
// your code here
}
或将结果数组存储在$data
$data = $this->M_reservation->all_order($awals, $akhirs, $status) ; // change here
// ...
// ...
foreach($data as $val){ // no change
// your code here
}
看看它是否对你有帮助。
- 1 回答
- 0 关注
- 109 浏览
添加回答
举报
0/150
提交
取消