简体   繁体   English

如何使用Maatwebsite Laravel导出带有电话号码格式数据的Excel

[英]How to export excel with phone number format data using Maatwebsite Laravel

I'm confused with laravel export using maatwebsite, I want to keep phone number data after exported with "+62" but the result is "62...". 我对使用maatwebsite的laravel export感到困惑,我希望在输出“+62”之后保留电话号码数据,但结果是“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"

] ]

And here's my code to export the data 这是我导出数据的代码

$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');

Please, help me to solve that problem (export the data with phone number format). 请帮我解决这个问题(用电话号码格式导出数据)。 Also if phone number in database "081..." then after exported is "81...". 此外,如果数据库“081 ...”中的电话号码,则导出后为“81 ...”。 I want to keep phone number in database full export to excel without changed format. 我希望将数据库完全导出的电话号码保存到excel而不更改格式。 Thank you in advance. 先感谢您。

Try changing the column format from: 尝试更改列格式:

'C' => "aaaaa"

...to: ...至:

'C' => "###-###-####"

...or: ...要么:

'C' => "[<=9999999]###-####;(###) ###-####"

Change the column format: 更改列格式:

[
    'D' => '+#'
]

I hope it helps. 我希望它有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 LARAVEL 9:如何使用 maatwebsite 根据过滤数据(id、月和年)将数据导出到 excel - LARAVEL 9: How to export data to excel based on filter data (id, month and years) using maatwebsite Laravel Maat网站\Excel 导出 - Laravel Maatwebsite\Excel export Laravel Maatwebsite导出到excel无法正常工作 - Laravel Maatwebsite Export to excel not working "使用 Maatwebsite \/ Laravel-Excel 导出带有超链接的合并单元格的 Excel" - Export Excel with merged cell with hyperlink using Maatwebsite / Laravel-Excel 如何在 laravel excel maatwebsite 中设置带分隔符的动态数字格式? - How Can I set dynamic number format with separator in laravel excel maatwebsite? 如何从Laravel 5.1中的Maatwebsite Excel中的模型导出特定属性 - How to export specific attributes from model in Maatwebsite Excel in Laravel 5.1 如何将动态页脚值添加到 maatwebsite/Laravel-Excel 导出 - How to add dynamic footer values to maatwebsite/Laravel-Excel export 如何从 Maatwebsite/Laravel-Excel package 中读取特定表号的数据? - How to read data from the specific sheet number from Maatwebsite/Laravel-Excel package? laravel maatwebsite excel 导出货币行 - laravel maatwebsite excel export currency row 如何在Laravel和maatwebsite 3.0中使用搜索值从视图导出数据 - How to export Data from view with Search values in Laravel and maatwebsite 3.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM