将php版本从7.0升级到7.1时出现问题。 我使用PHPExcel Laravel创建/导出xls文件。
错误消息是"遇到非正确形成的数值"。 但是当我将类型从xls更改为xlsx时,运行良好但格式不正确。 我认为问题是因为我升级了php版本。
已经尝试更改代码,修改,但一切都一样。 有人可以帮忙吗?
MyController看起来像:
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();
}
}
我的设置: Laravel 5.1 " maatwebsite / excel":" ~2.0", " phpoffice / phpword":" v0.13。*",
答案 0 :(得分:4)
这种情况通过检查每个HTML语法来解决。 例如,colspan / rowspan和每个行必须具有标准。如果第一行需要使用colspan 4,则后面的行也必须是相同的值。
因此,每种HTML语法都没有区别。当将导出('xls')更改为导出('xlsx')时,现在看起来很好。