Я использую CodeIgniter.Я экспортирую данные в таблицу Excel.
Теперь, что я делаю, у меня есть столбцы Payment option
и Payment Details
.
Я должен отобразить вывод в столбце, как
if(Payment option == 'a'){
//display array in the column
}
else if(Payment option == 'b')
{
//display array in the column
}
else{
//
}
Ожидаемый результат
Я получаю ошибку
1)
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 0
Filename: Cell/DefaultValueBinder.php
2)
A PHP Error was encountered
Severity: Warning
Message: preg_match() expects parameter 2 to be string, array given
Filename: Cell/DefaultValueBinder.php
Код экспорта
public function export_order_list(){
$object = new PHPExcel();
$object->setActiveSheetIndex(0);
$table_columns = array("Customer Name","Email","Mobile no","Alternet no","Payment option","Payment Details","Date of created");
$column = 0;
$object->getActiveSheet()->getStyle('1:1')->getFont()->setBold(true);
foreach($table_columns as $field)
{
$object->getActiveSheet()->setCellValueByColumnAndRow($column, 1, $field);
$column++;
}
$export_list = $this->Customer_model->export_order_list_model();//getting all data
$excel_row = 2;
foreach($export_list as $row)
{
$cust_name=$row->c_firstname." " .$row->c_middlename."".$row->c_lastname;
if ($row->payment_option=='A') {
$payment_details=array(
'Account holder name:' => $row->account_holder_name,
'Account no:'=>$row->e_account_no,
'Cheque no:'=>$row->cheque_no
);
}
if ($row->payment_option=='b') {
$payment_details=array(
'Name On Card:' => $row->c_name_on_card,
'Card Number:'=>$row->c_card_number,
'Exp month'=>$row->c_exp_month,
);
}
else{
$payment_details="";
}
$object->getActiveSheet()->setCellValueByColumnAndRow(0, $excel_row, $cust_name);
$object->getActiveSheet()->setCellValueByColumnAndRow(1, $excel_row, $row->c_email_id);
$object->getActiveSheet()->setCellValueByColumnAndRow(2, $excel_row, $row->c_mobileno);
$object->getActiveSheet()->setCellValueByColumnAndRow(3, $excel_row, $row->c_alternetno);
$object->getActiveSheet()->setCellValueByColumnAndRow(4, $excel_row, $row->payment_option);
$object->getActiveSheet()->setCellValueByColumnAndRow(5, $excel_row, $payment_details);
$object->getActiveSheet()->setCellValueByColumnAndRow(6, $excel_row, $row->c_date_of_added);
$excel_row++;
}
$object_writer = PHPExcel_IOFactory::createWriter($object, 'Excel5');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="Order list.xls"');
$object_writer->save('php://output');
}