patrickbrouwers
Repos
35
Followers
237
Following
1

🚀 Supercharged Excel exports and imports in Laravel

11393
1744

🚀 Supercharged Excel exports for Laravel Nova Resources

345
62

Events

Improve explanation of use of "AutoSize" (#205)

Created at 2 days ago
pull request closed
Improve explanation of use of "AutoSize"

In this way, I think it makes more understandable what is the key point in the code snippet, which is applying the "AutoSize" interface.

Created at 2 days ago
issue comment
[Bug]: Undefined array key 0 at /var/www/vendor/maatwebsite/excel/src/Row.php:97

As the code snippet you shared is not part of this package, it's not a bug. I would highly discourage using it like this. The package is not intended to be use that way and any upgrade can break it. Please use the package as documented and try and avoid internal classes.

Created at 2 days ago
[Bug]: Undefined array key 0 at /var/www/vendor/maatwebsite/excel/src/Row.php:97

Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?

  • [X] Yes, it's still reproducable

What version of Laravel Excel are you using?

^3.1

What version of Laravel are you using?

^8.0

What version of PHP are you using?

8.1.5

Describe your issue

We are iterating over cells using Maatwebsite\Excel\Row.php class. On Line 96, there is an if statement that is constantly throwing an error. This error has popped up since we upgraded to php 8.

if (!$this->headerIsGrouped[$i]) { Throws this error Undefined array key 0 {"exception":"[object] (ErrorException(code: 0): Undefined array key 0 at /var/www/vendor/maatwebsite/excel/src/Row.php:96

If I alter that if statement like so, it works if(!array_key_exists($i,$this->headerIsGrouped)){

Curious if this issue has also popped up with anyone else.

Looking for a work around or fix. Please reach out to me with any questions.

How can the issue be reproduced?

`try { foreach ($rows as $row) { $this->import->onRow(new Row($row, $headingRow)); } } catch (Throwable $e) { $this->wrapUp($sheet);

            throw $e;
        }`

What should be the expected behaviour?

The array key should return false, but it's throwing an exception

Created at 3 days ago
issue comment
[Bug]: Undefined array key 0 at /var/www/vendor/maatwebsite/excel/src/Row.php:97
try {
foreach ($rows as $row) {
$this->import->onRow(new Row($row, $headingRow));
}
} catch (Throwable $e) {
$this->wrapUp($sheet);

            throw $e;
        }

is not part of the this package, if you are trying to use internal classes of this package, you have to use them correctly and also pass in the third argument of the Row class which is headerIsGrouped. As these are internal classes, they are bound to change.

Created at 3 days ago
issue comment
[Bug]: Undefined array key 0 at /var/www/vendor/maatwebsite/excel/src/Row.php:97

Sounds like a specific situation, please try and provide a failing unit test via PR and if possible a fix.

Created at 3 days ago
Undefined array key "root"[Bug]:

Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?

  • [X] Yes, it's still reproducable

What version of Laravel Excel are you using?

3.1

What version of Laravel are you using?

9.75

What version of PHP are you using?

8.1

Describe your issue

Undefined array key "root"

How can the issue be reproduced?

Undefined array key "root"

What should be the expected behaviour?

Undefined array key "root"

Created at 3 days ago
issue comment
Undefined array key "root"[Bug]:

You are refering to a Laravel class, you are reporting the bug in the wrong repository

Created at 3 days ago
issue comment
Undefined array key "root"[Bug]:

Sounds like an issue in your own code. Maybe Stackoverflow can help you.

Created at 3 days ago
[Bug]: Exported PDFs with custom unicode font has unreadable (square) characters

Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?

  • [X] Yes, it's still reproducable

What version of Laravel Excel are you using?

3.1.30

What version of Laravel are you using?

9.19

What version of PHP are you using?

8.0.2

Describe your issue

Hi there! When exporting PDF files (using MPDF library) with custom unicode font (Noto Sans), Laravel Excel renders the characters as squares making them unreadable (like the image below).

What I'm actually trying to do is implement a custom unicode font that supports Devanagari in Laravel Excel exported PDFs.

To test for the file, I've created a blade template and created a PDF with just mPDF library and it gets the required result like this:

But when I try to export the same blade view with Laravel Excel, it gets the square characters like the first image shown. I've even tried to set the default font using the WithDefaultStyles concern as shown in the docs, like the image below but couldn't fix the issue:

Am I missing something here or Laravel Excel doesn't support any custom loaded unicode fonts? Would really help if someone could kindly enlighten me on this issue.

How can the issue be reproduced?

  1. Add this package to install mPDF driver and add Noto Sans as the default font of the driver (which is a Devanagari unicode font).
  2. Create a simple blade file with something like the following html table in Devanagari script. Export the PDF with just the mPDF driver using the above package, everything gets rendered as expected. Trying the same with Laravel Excel using the FromView concern (along with explicitly defining the font like the image code above) will return the unreadable square characters.

What should be the expected behaviour?

Exporting the PDF with just the standalone mPDF driver using the above package, everything gets rendered as expected. Trying the same with Laravel Excel using the FromView concern should generate the same pdf with the Devanagari unicode characters properly rendered. Maybe there's something missing with Laravel Excel & it's underlying unicode rendering process.

Created at 4 days ago
issue comment
[Bug]: Exported PDFs with custom unicode font has unreadable (square) characters

PDF is handled by PHPSpreadsheet, there's nothing this package can do to improve that. Best to report over there instead.

Created at 4 days ago
[Bug]: Background Error SplFileInfo::getSize(): stat failed for xxx

Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?

  • [X] Yes, it's still reproducable

What version of Laravel Excel are you using?

3.1.45

What version of Laravel are you using?

Lumen 6.3.3

What version of PHP are you using?

7.4.28

Describe your issue

Hi there,

This issue has already been submitted multiple times, but it seems it was abandoned in the closed thread, and pardon me for creating a new ticket. I've been using this package for 5 years, I hope I can help with the issue.

I got this issue on the lumen framework, actually, it's not breaking the download process, rather it only throws an output error on the storage/logs folder.

I got several results from this error, and I'm not sure it's all related:

  1. File was successfully downloaded, and I can open the file normally
  2. File was successfully downloaded, but when I open the file, it somehow corrupted (intermittent) image
  3. The result1-2 is if I'm using format .xlxs but if I'm using format .csv the error is printed on the file itself. I'm guessing this is connected with the second problem. image

My Guessing: When the download process begins, I try to check on var/app/storage/framework/cache/laravel-excel/ but no file is generated, I try to delete the laravel-excel folder, and It automatically created a new folder but it still empty. I think the error happened because the SplFileInfo::getSize(): read an undefined file.

Here is the permission for folder laravel-excel, I think you'd like the screenshot image

Here is the full log:

[2023-03-06 08:11:39] local.ERROR: SplFileInfo::getSize(): stat failed for /var/app/storage/framework/cache/laravel-excel/laravel-excel-qeT8Enpg54NpnZ9V3as7IeRa31899Uek.csv {"user-agent":"GuzzleHttp/7","url":"http://localhost/download","input":{"month":"03","year":"2023","page":"1"},"userId":1811,"exception":"[object] (RuntimeException(code: 0): SplFileInfo::getSize(): stat failed for /var/app/storage/framework/cache/laravel-excel/laravel-excel-qeT8Enpg54NpnZ9V3as7IeRa31899Uek.csv at /var/app/vendor/symfony/http-foundation/BinaryFileResponse.php:200) [stacktrace] #0 /var/app/vendor/symfony/http-foundation/BinaryFileResponse.php(200): SplFileInfo->getSize() #1 /var/app/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(438): Symfony\Component\HttpFoundation\BinaryFileResponse->prepare(Object(Illuminate\Http\Request)) #2 /var/app/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(133): Laravel\Lumen\Application->prepareResponse(Object(Symfony\Component\HttpFoundation\BinaryFileResponse)) #3 /var/app/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(117): Laravel\Lumen\Application->callTerminableMiddleware(Object(Symfony\Component\HttpFoundation\BinaryFileResponse)) #4 /var/app/public/index.php(28): Laravel\Lumen\Application->run() #5 {main} "}

How can the issue be reproduced?

I never reproduce this in another environment, but I think my code was simply enough

TicketExport.php

<?php

namespace Exports;

use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithStyles;
use PhpOffice\PhpSpreadsheet\Style\Fill;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;

class TicketExport implements FromArray, WithHeadings, WithMapping, ShouldAutoSize, WithStyles
{
    use Exportable;

    protected $tickets;

    public function __construct(array $tickets)
    {
        $this->tickets = $tickets;
    }
    
    public function styles(Worksheet $sheet)
    {
        $sheet->getStyle('A1:G1')->getFont()->setBold(true);
        $sheet->getStyle('A1:G1')->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setARGB('C5D9F1');
    }


    public function array(): array
    {
        return $this->tickets;
    }

    public function headings(): array
    {
        return [
            'ID',
            'Patient Name',
            'Clinic Name',
            'Approved Date',
            'Deadline Date',
            'Completed Date',
            'Notes',
        ];
    }

    public function map($tickets): array
    {

        return [
            $tickets['id'],
            $tickets['name'],
            $tickets['clinic'],
            $tickets['approved_date'],
            $tickets['deadline_date'],
            $tickets['completed_date'],
            $tickets['notes'],
        ];
    }
}

My Controller:

    public function download(Request $request)
    {
        $this->validate($request, [
            'month' => 'required',
            'year' => 'required',
        ]);

        $ticket = $this->service->getDownloadList($request);
        
        return (new ProductionTicketExport($productionTicket))->download("Ticket $request->month-$request->year.xlsx", \Maatwebsite\Excel\Excel::XLSX);
    }

What should be the expected behaviour?

I expect no error thrown after downloading the file

Created at 4 days ago
issue comment
[Bug]: Background Error SplFileInfo::getSize(): stat failed for xxx

Looks like your api response is outputting to the buffer. As you are using download, everything is prepended to that output-buffer. https://www.php.net/manual/en/function.ob-clean.php

Created at 4 days ago
[Bug]: laravel excel header contains column name zero

Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?

  • [X] Yes, it's still reproducable

What version of Laravel Excel are you using?

^3.1

What version of Laravel are you using?

^8.0

What version of PHP are you using?

7.4

Describe your issue

I making a dynamic excel sheet to export and fill with data and upload it, when the user names one of the items zero(0) I can't get the value of this column because it changed to the index of the column names

excel

How can the issue be reproduced?

.

What should be the expected behaviour?

show the key zero not the column index

Created at 4 days ago
issue comment
[Bug]: laravel excel header contains column name zero

Change the heading formatter to your liking: https://github.com/SpartnerNL/Laravel-Excel/blob/3.1/config/excel.php#L114

Created at 4 days ago
[Bug]: Sheets method called twice

Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?

  • [X] Yes, it's still reproducable

What version of Laravel Excel are you using?

3.1.48

What version of Laravel are you using?

9.52.4

What version of PHP are you using?

8.1.12

Describe your issue

When creating a multi-sheet export, the sheets method is called twice. This causes all the queries each sheet to be run twice which can be significant for an export with many sheets and a lof of data.

Could the call in WriterFactory::includesCharts() be handled in such a way that doesn't require a second instantiation of all the sheets?

    private static function includesCharts($export): bool
    {
        if ($export instanceof WithCharts) {
            return true;
        }

        if ($export instanceof WithMultipleSheets) {
            foreach ($export->sheets() as $sheet) {
                if ($sheet instanceof WithCharts) {
                    return true;
                }
            }
        }

        return false;
    }

How can the issue be reproduced?

Create a multi-sheet export and download it.

What should be the expected behaviour?

The method to be called once.

Created at 4 days ago
issue comment
[Bug]: Sheets method called twice

That's not possible. Make sure your logic inside sheet can be executed multiple times, either by handling the logic in the constructor or by caching it

Created at 4 days ago
issue comment
[Bug]: Excel::Import error preg_match(): No ending matching delimiter ')' found

Please share the full stacktrace, it's not clear which file throws the error. It sounds like an error in your own code

Created at 4 days ago
issue comment
[Bug]: Field with string percentage "%" why always auto converted to float

That's expected behaviour. A percentage is always a float.

'discount' => $row[2] * 100,
Created at 4 days ago
[Bug]: Field with string percentage "%" why always auto converted to float

Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?

  • [X] Yes, it's still reproducable

What version of Laravel Excel are you using?

3.1

What version of Laravel are you using?

9.19

What version of PHP are you using?

8.0.2

Describe your issue

I have excel file with like this pic image

in my imports code tried to replace % with "", but it's never replace because when I tried to print value, the value is 0.3 not 30% anymore. So I am assuming when data goes to function model the value is already converted to float.

my target result is check value contains % or no, if yes then replace with "". I just want to get number only in this case is 30

<?php

namespace App\Imports;

use App\Models\Ekspedisi;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithStartRow;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;

class ImportEkspedisi implements ToModel, WithStartRow, WithMultipleSheets
{
    /**
    * @param array $row
    *
    * @return \Illuminate\Database\Eloquent\Model|null
    */
    public function model(array $row)
    {
        return new Ekspedisi([
            'id' => $row[0],
            'ekspedisi' => $row[1],
            'discount' => str_replace("%", "", $row[2]),
            'disc_on_customer' => str_replace("%", "", $row[3]),
            'cod_fee' => str_replace("%", "", $row[4]),
            'insurance_fee' => str_replace("%", "", $row[5]),
            'is_aktif' => "aktif"
        ]);

        
    }

    public function startRow(): int
    {
        return 2; // row pertama adalah judul
    }

    public function sheets(): array
    {
        return [
            0 => new ImportEkspedisi(),
        ];
    }
}

How can the issue be reproduced?

I have excel file with like this pic image

in my imports code tried to replace % with "", but it's never replace because when I tried to print value, the value is 0.3 not 30% anymore. So I am assuming when data goes to function model the value is already converted to float.

my target result is check value contains % or no, if yes then replace with "". I just want to get number only in this case is 30

<?php

namespace App\Imports;

use App\Models\Ekspedisi;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithStartRow;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;

class ImportEkspedisi implements ToModel, WithStartRow, WithMultipleSheets
{
    /**
    * @param array $row
    *
    * @return \Illuminate\Database\Eloquent\Model|null
    */
    public function model(array $row)
    {
        return new Ekspedisi([
            'id' => $row[0],
            'ekspedisi' => $row[1],
            'discount' => str_replace("%", "", $row[2]),
            'disc_on_customer' => str_replace("%", "", $row[3]),
            'cod_fee' => str_replace("%", "", $row[4]),
            'insurance_fee' => str_replace("%", "", $row[5]),
            'is_aktif' => "aktif"
        ]);

        
    }

    public function startRow(): int
    {
        return 2; // row pertama adalah judul
    }

    public function sheets(): array
    {
        return [
            0 => new ImportEkspedisi(),
        ];
    }
}

What should be the expected behaviour?

I have excel file with like this pic image

in my imports code tried to replace % with "", but it's never replace because when I tried to print value, the value is 0.3 not 30% anymore. So I am assuming when data goes to function model the value is already converted to float.

my target result is check value contains % or no, if yes then replace with "". I just want to get number only in this case is 30

<?php

namespace App\Imports;

use App\Models\Ekspedisi;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithStartRow;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;

class ImportEkspedisi implements ToModel, WithStartRow, WithMultipleSheets
{
    /**
    * @param array $row
    *
    * @return \Illuminate\Database\Eloquent\Model|null
    */
    public function model(array $row)
    {
        return new Ekspedisi([
            'id' => $row[0],
            'ekspedisi' => $row[1],
            'discount' => str_replace("%", "", $row[2]),
            'disc_on_customer' => str_replace("%", "", $row[3]),
            'cod_fee' => str_replace("%", "", $row[4]),
            'insurance_fee' => str_replace("%", "", $row[5]),
            'is_aktif' => "aktif"
        ]);

        
    }

    public function startRow(): int
    {
        return 2; // row pertama adalah judul
    }

    public function sheets(): array
    {
        return [
            0 => new ImportEkspedisi(),
        ];
    }
}

Created at 4 days ago
[Bug]: Export From View Using ColSpan is broken layout

Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?

  • [X] Yes, it's still reproducable

What version of Laravel Excel are you using?

3.1.44

What version of Laravel are you using?

8.83.27

What version of PHP are you using?

8.1.0

Describe your issue

I am using export feature from view. When i use colspan from Y column, it is not working and broken layout. 2023-03-21_10-19

How can the issue be reproduced?

This is html code after generate

What should be the expected behaviour?

Need colspan from column Y correct, correct layout (not broken)

Created at 4 days ago
issue comment
[Bug]: Export From View Using ColSpan is broken layout

Colspans in html are handled by phpspreadsheet, best to report over there.

Created at 4 days ago
issue comment
[Bug]: Class "ZipArchive" not found

You probably need to restart your xampp. Best to ask help on Stackoverflow as this is not a bug in this package

Created at 2 weeks ago
[Bug]: Class "ZipArchive" not found

Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?

  • [X] Yes, it's still reproducable

What version of Laravel Excel are you using?

3.1

What version of Laravel are you using?

9.x

What version of PHP are you using?

8.x

Describe your issue

whenever im trying to import excel file, im get Class "ZipArchive" not found

How can the issue be reproduced?

This is my import file

 public function model(array $row)
    {
        return new Inventaris([
            "nama_user" => $row[1],
            "bagian_id" => $row[2],
            "th_pembelian" => $row[3],
            "memory" => $row[4],
            "cpu" => $row[5],
            "kode" => $row[6],
            "merk" => $row[7],
            "keterangan" => $row[8],
            "posisi" => $row[9],
            "size_monitor" => $row[10],
            "kategori_id" => $row[11],
            "status_id" => $row[12],
        ]);
    }

What should be the expected behaviour?

I was enable zip extention in my php.ini file (im using xampp by the way) but still get error like that

Created at 2 weeks ago
pull request reopened
Add configuration option to configure permissions of local temporary directory (and files)

Please take note of our contributing guidelines: https://docs.laravel-excel.com/3.1/getting-started/contributing.html Filling out the template is required. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.

1️⃣ Why should it be added? What are the benefits of this change? The current code doesn't use the configured permissions of Laravel filesystem. See #3766

2️⃣ Does it contain multiple, unrelated changes? Please separate the PRs out. No.

3️⃣ Does it include tests, if possible? Yes, a new test was added to test the behaviour of TemporaryFileFactory

4️⃣ Any drawbacks? Possible breaking changes? Code is backwards compatible

5️⃣ Mark the following tasks as done:

  • [x] Checked the codebase to ensure that your feature doesn't already exist.
  • [x] Take note of the contributing guidelines.
  • [x] Checked the pull requests to ensure that another person hasn't already submitted a fix.
  • [x] Added tests to ensure against regression.
  • [x] Updated the changelog

6️⃣ Thanks for contributing! 🙌

Created at 2 weeks ago

Deal with older phpspreadsheet versions for older php versions performing a different column formatting

Created at 3 weeks ago

Update tests to reflect changes in Phpspreadsheet 1.28

Created at 3 weeks ago
issue comment
[Bug]: Database connection [*] not configured when using exists validation rule

Best to provide a PR then, I have no idea what the issue is and currently no time (nor priority) to dive into this

Created at 3 weeks ago