Improve explanation of use of "AutoSize" (#205)
In this way, I think it makes more understandable what is the key point in the code snippet, which is applying the "AutoSize" interface.
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.
^3.1
^8.0
8.1.5
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.
`try { foreach ($rows as $row) { $this->import->onRow(new Row($row, $headingRow)); } } catch (Throwable $e) { $this->wrapUp($sheet);
throw $e;
}`
The array key should return false, but it's throwing an exception
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.
Sounds like a specific situation, please try and provide a failing unit test via PR and if possible a fix.
3.1
9.75
8.1
Undefined array key "root"
Undefined array key "root"
Undefined array key "root"
You are refering to a Laravel class, you are reporting the bug in the wrong repository
Sounds like an issue in your own code. Maybe Stackoverflow can help you.
3.1.30
9.19
8.0.2
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.
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.
PDF is handled by PHPSpreadsheet, there's nothing this package can do to improve that. Best to report over there instead.
3.1.45
Lumen 6.3.3
7.4.28
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:
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
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} "}
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);
}
I expect no error thrown after downloading the file
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
^3.1
^8.0
7.4
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
.
show the key zero not the column index
Change the heading formatter to your liking: https://github.com/SpartnerNL/Laravel-Excel/blob/3.1/config/excel.php#L114
3.1.48
9.52.4
8.1.12
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;
}
Create a multi-sheet export and download it.
The method to be called once.
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
Please share the full stacktrace, it's not clear which file throws the error. It sounds like an error in your own code
That's expected behaviour. A percentage is always a float.
'discount' => $row[2] * 100,
3.1
9.19
8.0.2
I have excel file with like this pic
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(),
];
}
}
I have excel file with like this pic
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(),
];
}
}
I have excel file with like this pic
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(),
];
}
}
3.1.44
8.83.27
8.1.0
I am using export feature from view. When i use colspan from Y column, it is not working and broken layout.
This is html code after generate
Need colspan from column Y correct, correct layout (not broken)
Colspans in html are handled by phpspreadsheet, best to report over there.
You probably need to restart your xampp. Best to ask help on Stackoverflow as this is not a bug in this package
3.1
9.x
8.x
whenever im trying to import excel file, im get Class "ZipArchive" not found
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],
]);
}
I was enable zip
extention in my php.ini
file (im using xampp
by the way) but still get error like that
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:
6️⃣ Thanks for contributing! 🙌
Deal with older phpspreadsheet versions for older php versions performing a different column formatting
Update tests to reflect changes in Phpspreadsheet 1.28
Best to provide a PR then, I have no idea what the issue is and currently no time (nor priority) to dive into this