Bobby
Bobby

Reputation: 254

A non well formed numeric value encountered on PHPExcel Laravel

I got a problem when upgrade php version from 7.0 to 7.1. I'm using PHPExcel Laravel to create/export xls file.

The error message is "A non well formed numeric value encountered". But when i change the type from xls to xlsx, running well but bad format. I think the problem is because i upgraded the php version.

Already try to change the code, modify, but everything is same. Anyone can help ?

MyController looks like :

public function exportPo(Request $request)
{
    try{
        if($request->getMethod() == 'POST'){
            $input = $request->all();   

            $validator = Validator::make($input, [
                'start_date' => 'required|date',
                'end_date' => 'required|date',
            ]);

            if ($validator->fails()) {
                return redirect(route('export-po'))
                    ->withErrors($validator)
                    ->withInput();
            }

            $postData = [];
            $postData['search_term']['date'] = [
                'start_date'=> $input['start_date'],
                'end_date'=> $input['end_date']
            ];

            if(count($postData) > 0){
                //Export the excel file here
                $poList = EprocModel::getPostData('/listPurchaseOrder', $postData);
                $poListArr = json_decode($poList, true);
                if(isset($poListArr['data'])){
                    $row = [];
                    foreach($poListArr['data'] as $data){
                        switch($data['status_po']){
                            case 0:
                                $status = 'Baru';
                                break;
                            case 2:
                                $status = "Reject";
                                break;
                            case 3:
                                $status = "Cancel";
                                break;
                            case 1:
                                if(
                                    $data['status_shipping'] == 0 &&
                                    $data['status_payment_buyer'] == 0 &&
                                    $data['status_payment_seller'] == 0
                                ){
                                    $status = "Processing";
                                }
                                if(
                                    $data['status_shipping'] == 1 &&
                                    $data['status_payment_buyer'] == 0 &&
                                    $data['status_payment_seller'] == 0
                                ){
                                    $status = "Shipping";
                                }

                                if(
                                    $data['status_shipping'] == 2 &&
                                    $data['status_payment_buyer'] == 0 &&
                                    $data['status_payment_seller'] == 0
                                ){
                                    $status = "Shipping";
                                }

                                if(
                                    $data['status_shipping'] == 2 &&
                                    $data['status_payment_buyer'] == 1 &&
                                    $data['status_payment_seller'] == 1
                                ){
                                    $status = "Closed";
                                }
                                break;
                            default:
                                $status = "unknown";
                                break;
                        }
                        $row[] = [
                            'PO. No'=> $data['po_number'],
                            'PR. No'=> $data['pr_number'],
                            'Type (Direct/Indirect)'=> ($data['company_type'] == 1 ? "Direct" : "Indirect"),
                            'Requestor/Customer'=> $data['buyer_name'],
                            'Fulfillment'=> $data['seller_name'],
                            'Status'=>$status,
                            'Catatan Pembelian'=> $data['notes']
                        ];
                    }
                    Excel::create('purchase_order', function($excel) use ($row){
                        $excel->sheet('purchase order', function($sheet) use ($row) {
                            $sheet->fromArray($row, null, 'A1', true, true);

                            //Change background color for the first row to grey
                            $sheet->row(1, function($row) {
                                $row->setBackground('#cccccc');

                            });
                        });
                    })->export('xls');
                }else{
                    \Session::flash('error', $poListArr['errors']['userMessage']);
                }
            }
        }
        Theme::asset()->serve('form');
        return $this->theme->scope('finances.exportPo')->render();
    }catch(\Exception $e){
        return $e->getMessage();
    }
}

My Setup : Laravel 5.1 "maatwebsite/excel": "~2.0", "phpoffice/phpword": "v0.13.*",

Upvotes: 0

Views: 6770

Answers (1)

Bobby
Bobby

Reputation: 254

This case solve by checking every HTML syntax. For ex, , colspan/rowspan and anything must be has standard for every each row. If the first row need to use colspan 4 , the rows after must be same value also.

So, there are no different for every HTML syntax. And when changing export('xls') to export('xlsx') , looks good now.

Upvotes: 5

Related Questions