
Introduction
When exporting orders or customer data from a Laravel application using the Maatwebsite/Excel package, you might encounter an issue where phone numbers appear in scientific notation (e.g., 5.35477E+11) in Excel. This happens because Excel automatically converts large numbers into exponential format.
In this blog, I’ll walk you through how to properly format phone numbers in Laravel Excel exports to ensure they display as regular numbers.
Setting Up Excel Export in Laravel
To export an Excel file from a Laravel application, we use the Maatwebsite/Excel package. If you haven’t installed it yet, you can do so with:
shCopyEditcomposer require maatwebsite/excel
After installation, create an export class:
shCopyEditphp artisan make:export OrdersExport --model=Orders
Now, let’s configure this export class.
Defining the Export Class
Here’s the OrdersExport.php file where we define the export logic using the FromView concern:
phpCopyEdit<?php
namespace App\Exports;
use App\Models\Orders;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class OrdersExport implements FromView
{
public function view(): View
{
$orders = Orders::select('receipt_id', 'table', 'customer', 'phone', 'type', 'status', 'discount', 'total', 'created_at')
->orderBy('id', 'desc')
->get();
return view('admin.export', compact('orders'));
}
}
Creating the Controller Method for Exporting
Inside OrdersController.php, we create an export() method that triggers the Excel download:
phpCopyEdituse Maatwebsite\Excel\Facades\Excel;
use App\Exports\OrdersExport;
public function export()
{
return Excel::download(new OrdersExport, 'orders.xlsx');
}
This method generates an Excel file and downloads it.
The Issue: Phone Numbers in Scientific Notation
When opening the exported Excel file, phone numbers appear in an exponential format like this:
mathematicaCopyEdit5.35477E+11
This happens because Excel assumes long numbers are mathematical values and automatically applies scientific notation.
How to Fix It?
We need to format the phone number as text so Excel does not interpret it as a number. The best way to do this is by modifying the Blade template used for export.
Fixing Phone Number Formatting in Blade Template
Locate the Blade file responsible for rendering the export (resources/views/admin/export.blade.php). Update the <td> where phone numbers are displayed:
bladeCopyEdit<td>{{ "=\"" . $items->phone . "\"" }}</td> {{-- Force Excel to treat as text --}}
Why Does This Work?
- The =”1234567890″ format ensures Excel recognizes the value as a text string instead of a number.
- Excel treats anything inside =”…” as text and doesn’t apply scientific notation.
Updated Blade Template
Here is the complete, corrected Blade file:
bladeCopyEdit<table>
<thead>
<tr>
<th>Order Id</th>
<th>Table No.</th>
<th>Customer</th>
<th>Phone</th>
<th>Price</th>
<th>Discount</th>
<th>Type</th>
<th>Status</th>
<th>Date</th>
</tr>
</thead>
<tbody>
@if ($orders->isNotEmpty())
@foreach ($orders as $items)
<tr>
<td>{{ $items->receipt_id }}</td>
<td>{{ $items->table }}</td>
<td>{{ $items->customer }}</td>
<td>{{ "=\"" . $items->phone . "\"" }}</td> {{-- Fix applied here --}}
<td>Rs. {{ number_format($items->total, 2) }}</td>
<td>Rs. {{ number_format($items->discount, 2) }}</td>
<td>{{ $items->type }}</td>
<td>{{ $items->status }}</td>
<td>
{{ date('Y-m-d', strtotime($items->created_at)) }} <br>
{{ date('h:i A', strtotime($items->created_at)) }}
</td>
</tr>
@endforeach
@endif
</tbody>
</table>
Alternative Fix (Prefixing with a Tab Character)
Another method is to prepend a tab character (\t) to the phone number:
bladeCopyEdit<td>{{ "\t" . $items->phone }} </td>
However, this may not always work reliably across different Excel versions.
Final Thoughts
By applying this fix, you ensure that phone numbers are displayed correctly in Excel exports, without scientific notation.
If you’re working with Laravel and Excel exports, formatting issues like this can be frustrating, but simple solutions like forcing text formatting can make a big difference.
✅ Now your exported Excel files will show proper phone numbers instead of exponential notation! 🚀