如何使用 Maatwebsite Laravel 以 phone 数字格式数据导出 excel
How to export excel with phone number format data using Maatwebsite Laravel
我对使用 maatwebsite 导出 laravel 感到困惑,我想在使用“+62”导出后保留 phone 数字数据,但结果是“62...”。
0 => array:17 [▼
"created_at" => "13 Sep 2016 @ 04:37:16"
"merchant_name" => "XXX"
"merchant_email" => "XXX"
"merchant_phone" => "+6281290926402"
"merchant_address" => """
XXX
"""
"instagram_id" => "XXX"
"facebook_account" => "XXX"
"bank_name" => "CIMB Niaga"
"branch_name" => "XXX"
"province_name" => "DKI JAKARTA"
"city_name" => "JAKARTA SELATAN"
"district_name" => "CILANDAK"
"subdistrict_name" => "CIPETE SELATAN"
"postal_code" => "12410"
"account_name" => "XXX"
"account_number" => "XXX"
"merchant_status" => "active"
]
这是我导出数据的代码
$result = Excel::create('Merchant Recap - '.$day.' '.$month.' '.$year.' '.$hour.':'.$minute.':'.$second, function ($excel) use ($day, $month, $year, $hour, $minute, $second, $data) {
$excel->sheet('Order Recap', function($sheet) use ($day, $month, $year, $hour, $minute, $second, $data) {
$row = 1;
$sheet->row($row, array('Merchant Name', 'Merchant Email', 'Merchant Phone', 'Merchant Address', 'Instagram', 'Facebook', 'Bank of Merchant', 'Branch', 'Province', 'City', 'District', 'Subdistrict', 'Postal Code', 'Account Name', 'Account Number', 'Status', 'Created Date'));
$sheet->cells('A'.$row.':Q'.$row, function($cells) {
$cells->setFont(array(
'size' => 12,
'bold' => true
));
});
$row++;
$sheet->setColumnFormat([
'C' => "aaaaa",
'O' => "#",
'Q' => "dd mmmm yyyy HH:mm:ss"
]);
foreach ($data as $key => $merchant) {
$sheet->row
($row, array(
$merchant->merchant_name
,$merchant->merchant_email
,$merchant->merchant_phone
....
,PHPExcel_Shared_Date::PHPToExcel(strtotime($created_at))
));
$sheet->getStyle('A'.$row.':Q'.$row)->getAlignment()->applyFromArray(
array('horizontal' => 'left')
);
$row++;
}
$sheet->setAutoFilter('A4:Q4');
});
})->export('xls');
请帮我解决这个问题(导出 phone 数字格式的数据)。此外,如果 phone 数据库中的数字“081...”,则导出后为“81...”。我想保留 phone 数据库中的数字完全导出到 excel 而不更改格式。提前谢谢你。
尝试更改列格式:
'C' => "aaaaa"
...至:
'C' => "###-###-####"
...或者:
'C' => "[<=9999999]###-####;(###) ###-####"
更改列格式:
[
'D' => '+#'
]
希望对您有所帮助。
我对使用 maatwebsite 导出 laravel 感到困惑,我想在使用“+62”导出后保留 phone 数字数据,但结果是“62...”。
0 => array:17 [▼
"created_at" => "13 Sep 2016 @ 04:37:16"
"merchant_name" => "XXX"
"merchant_email" => "XXX"
"merchant_phone" => "+6281290926402"
"merchant_address" => """
XXX
"""
"instagram_id" => "XXX"
"facebook_account" => "XXX"
"bank_name" => "CIMB Niaga"
"branch_name" => "XXX"
"province_name" => "DKI JAKARTA"
"city_name" => "JAKARTA SELATAN"
"district_name" => "CILANDAK"
"subdistrict_name" => "CIPETE SELATAN"
"postal_code" => "12410"
"account_name" => "XXX"
"account_number" => "XXX"
"merchant_status" => "active"
]
这是我导出数据的代码
$result = Excel::create('Merchant Recap - '.$day.' '.$month.' '.$year.' '.$hour.':'.$minute.':'.$second, function ($excel) use ($day, $month, $year, $hour, $minute, $second, $data) {
$excel->sheet('Order Recap', function($sheet) use ($day, $month, $year, $hour, $minute, $second, $data) {
$row = 1;
$sheet->row($row, array('Merchant Name', 'Merchant Email', 'Merchant Phone', 'Merchant Address', 'Instagram', 'Facebook', 'Bank of Merchant', 'Branch', 'Province', 'City', 'District', 'Subdistrict', 'Postal Code', 'Account Name', 'Account Number', 'Status', 'Created Date'));
$sheet->cells('A'.$row.':Q'.$row, function($cells) {
$cells->setFont(array(
'size' => 12,
'bold' => true
));
});
$row++;
$sheet->setColumnFormat([
'C' => "aaaaa",
'O' => "#",
'Q' => "dd mmmm yyyy HH:mm:ss"
]);
foreach ($data as $key => $merchant) {
$sheet->row
($row, array(
$merchant->merchant_name
,$merchant->merchant_email
,$merchant->merchant_phone
....
,PHPExcel_Shared_Date::PHPToExcel(strtotime($created_at))
));
$sheet->getStyle('A'.$row.':Q'.$row)->getAlignment()->applyFromArray(
array('horizontal' => 'left')
);
$row++;
}
$sheet->setAutoFilter('A4:Q4');
});
})->export('xls');
请帮我解决这个问题(导出 phone 数字格式的数据)。此外,如果 phone 数据库中的数字“081...”,则导出后为“81...”。我想保留 phone 数据库中的数字完全导出到 excel 而不更改格式。提前谢谢你。
尝试更改列格式:
'C' => "aaaaa"
...至:
'C' => "###-###-####"
...或者:
'C' => "[<=9999999]###-####;(###) ###-####"
更改列格式:
[
'D' => '+#'
]
希望对您有所帮助。