The provided code is a Laravel Excel export class named CustomerExport that implements several interfaces for exporting order data to an Excel file. The class defines the exported Excel sheet's structure, formatting, and content.
The startRow() method is intended to specify the row number where the data should start printing, which is set to 10 in this case. However, despite this setting, the data appears to be printing from a different row, causing an issue.
The collection() method retrieves the order data from the database, along with related models like customers, health insurance, and users. It then maps this data into an array format suitable for exporting to Excel.
The headings() method defines the column headings for the Excel sheet, including empty rows for spacing and additional information like row numbers.
Despite the startRow() method specifying row 10 as the starting point for data printing, it appears that the data is not being printed from that row. This could be due to an issue with the implementation of the startRow() method or a conflict with the formatting and layout operations performed in the registerEvents() method.
To resolve the issue, you may need to review the code and ensure that the startRow() method is being correctly implemented and that there are no conflicts with the formatting operations in the registerEvents() method that could be overriding or affecting the specified start row.
public function startRow(): int
{
return 10;
}
/**
* @return \Illuminate\Support\Collection
*/
public function collection()
{
$data = Order::with(['customer', 'HealthInsurance','HealthInsurance.KCBPlace' ,'user'])
->get()
->map(function ($order,$index) {
$data = [
'STT' => $index + 10, // Số thứ tự
'Họ và tên' => $order->customer ? $order->customer->fullname : null,
'Mã số BHXH' => $order->customer ? $order->customer->insurance_code : null,
'CCCD'=> $order->customer ? $order->customer->identifier : null,
'Ngày sinh' => $order->customer ? $order->customer->birthdate : null,
'Giới tính'=> $order->customer ? $order->customer->gender : null,
'Địa chỉ'=> $order->customer ? $order->customer->birthplace : null,
'KCB' => $order->HealthInsurance? $order->HealthInsurance->KCBPlace->name : null,
'Ngày biên lai' => $order->HealthInsurance ? $order->HealthInsurance->document_approval_date : null,
'Sô biên lai' => $order->HealthInsurance ? $order->HealthInsurance->receipt_code : null,
'Số tiền' => $order->price,
'Từ tháng' => $order->HealthInsurance ? $order->HealthInsurance->starting_date : null,
'Số tháng' => $order->HealthInsurance ? $order->HealthInsurance->months : null,
'Mã nhân viên thu' => $order->user ? $order->user->id : null,
];
return $data;
});
return collect($data);
}
I tried using the startRow() method, which specifies the row number where the data should start printing. However, this approach did not work, and the data was still not printing from the expected starting row. Additionally, I attempted to use the startCell() method, which allows me to set the starting cell (row and column) for printing the data. Despite using this method, the issue persisted, and the data was not being printed from the desired starting row.
I tried disabling the registerEvents() method in I code to troubleshoot the issue further. This method is responsible for various formatting and laIt operations on the Excel sheet, such as merging cells, setting cell values, applying styles, and adjusting row heights.
By disabling registerEvents(), I wanted to determine if the logic or operations caused the issue within this method. If the problem was resolved by disabling registerEvents(), it would indicate that the root cause lies within that method. However, if the issue persisted even after disabling registerEvents(), the problem might be located elsewhere in Ir code or within the implementation of the Excel Export library itself.
Despite trying these different approaches, including specifying the start row using startRow() and startCell() and disabling the registerEvents() method, I have not been able to resolve the issue of data not printing from the specified starting row.