spartnernl / laravel-nova-excel Goto Github PK
View Code? Open in Web Editor NEWπ Supercharged Excel exports for Laravel Nova Resources
Home Page: https://docs.laravel-excel.com/nova/1.0/
License: MIT License
π Supercharged Excel exports for Laravel Nova Resources
Home Page: https://docs.laravel-excel.com/nova/1.0/
License: MIT License
[Y] Able to reproduce the behaviour outside of your code, the problem is isolated to Laravel Excel.
[Y] Checked that your issue isn't already filed.
[Y] Checked if no PR was submitted that fixes this problem.
PHP version: 7.3
Laravel version: 5.8.17
Nova version: 2.0.5
Package version: 3.1.13 and 1.1.4
I've got more than 10, 000 records in my table. When I use Download Excel
, it just nothing happens even though I use the chunk method.
((new DownloadExcel())->withHeadings()->withChunkCount(300)),
I thought it may work in chunk mode, but seems not.
PHP version: 7.2
The
...Text::make('Estimate Revenue', function() { return $this->slips->price; })->sortable()...
below doesn't work with this plugin.
Error: message: "Trying to get property of non-object"
public function fields(Request $request)
{
return [
ID::make()->sortable(),
// I'm 100% sure slips and price is defined, it appears on nova tables
Text::make('Estimate Revenue', function() { return $this->slips->price; })->sortable(),
...
Simply add a closure like the one above.
Expected behavior:
Just export.
Actual behavior:
Error: message: "Trying to get property of non-object"
Prove that $this->slips->price;
is defined: https://i.imgur.com/FsOr1dH.png
Actually this is no issue but a question. I have two models: Projects, Members. Each project has many members.
What I want to do? I want to export a list (xlsx) of all members for one project. I've created a Member's action. Then I have to select all members and run my action.
What I want to do instead? I want to run an action on a single project, getting all members. It this possible?
If this is the wrong place for questions like this, I apologize. Thank you for your help!
Nova v1.0.16 & Nova Excel v1.0.4
When using lenses as described in the nova docs and adding columns like so
public static function query(LensRequest $request, $query)
{
return $request->withOrdering($request->withFilters(
$query->select([
'id',
\DB::raw('YEAR(`created_at`) AS `year`'),
\DB::raw('QUARTER(`created_at`) AS `quarter`'),
\DB::raw('MONTHNAME(`created_at`) AS `month`'),
])
));
}
public function fields(Request $request)
{
return [
ID::make('ID', 'id')->sortable(),
Text::make('Year')->sortable(),
Text::make('Quarter')->sortable(),
Text::make('Month')->sortable(),
];
}
Although it displays as intended, the downloaded file only includes the ids
The raw selects are empty in the resulting file
Activate the action log following nova documentation https://nova.laravel.com/docs/1.0/actions/defining-actions.html#action-log
(adding use Actionable to the model that refers to resource that has ExportToExcel or DownloadExcel action)
If you activate the Action log, when you export something you should see the log inside the single view of the resource. This does not happen. I tried other actions and those are being logged correctly.
Expected behavior:
Create a new log of the performed action
Actual behavior:
Nothing is created
Hey there! Great package, love the Excel Downloads! Any chance it's possible to download a Nova Resource as a PDF?
The file downloaded is not opening. Giving a UTF8 Malformed error
Expected File to Open but giving error
Expected behavior:
Actual behavior:
Any additional information, configuration or data that might be necessary to reproduce the issue.
Installed correctly, php7.2, laravel 5.6.38, orion 1.0.13.
added to actions array on a simple model with just one string field and id field
select all models on index view, run download excel action. request is sent, query is executed, but no response is received and no success message returned. nothing in error logs.
haven't dug very deep to diagnose. does anyone one else have issues?
When exporting a column of data set as decimal(8.2)
in MySQL, the column will only add data to the CSV file if the entry is greater than 0.00.
I also noticed that boolean false
gets omitted as if it were null, as well. It sounds a lot like something somewhere is using empty()
to check if something should be set to an empty string in the CSV.
I don't have time right now to look into it further, but hopefully the package maintainer or someone else will look into the issue. (FYI, to keep things simple, a 0
in lieu of a boolean false
would be great in the CSV.)
When downloading from a nova lens, it does not use the lens columns but rather the main resource
The reason I think this is important to address is
I figured a work around to making a custom file for a specific case would be lenses
VERY useful to say "Go to lens > select specific export lens > click download action"
I've set up a QueuedExport
and am using ->withHeadings()
but headings are not being prepended to my export.
(new QueuedExport())
->withHeadings('ID', 'First Name', 'Last Name', 'Email', 'Phone', 'City', 'State', 'Zip', 'Status')
->only('id', 'first_name', 'last_name', 'email', 'phone', 'city', 'region', 'postal_code', 'worker_status')
->withDisk(config('filesystems.default'))
->withFilename($export_filename)
->onSuccess(function (ActionRequest $request, PendingDispatch $queue) use ($export_filename) {
$queue
->allOnQueue('default')
->chain([
new NotifyUserOfCompletedExport(
$request->user(),
$export_filename,
Storage::temporaryUrl($export_filename, Carbon::now()->addWeek())
),
]);
return Action::message('Your export is queued. You will be notified when it\'s ready.');
}),
The DownloadExcel
action'name is 'Download Excel' by default, I want to display it Chinese like "δΈθ½½θ‘¨ζ Ό",
Then I use the withName()
method to change it, the action button is disabledγ
// disabled with chinese
(new DownloadExcel)->withName('δΈθ½½θ‘¨ζ Ό')
// abled with english
(new DownloadExcel)->withName('Download')
I got this error when export to PDF
local.ERROR: unlink(C:\Users\user\AppData\Local\Temp\qtsingleapp-lineex-3e70-1-lockfile): Resource temporarily unavailable
---- To fix this issue as my temporary solution ----
Open file ...\vendor\mpdf\mpdf\src\Cache.php
Add this code to __construct
`
public function __construct($basePath, $cleanupInterval = 3600)
{
if (!$this->createBasePath($basePath)) {
throw new \Mpdf\MpdfException(sprintf('Temporary files directory "%s" is not writable', $basePath));
}
$this->basePath = config('excel.exports.temp_path', $basePath); // <-- I add this code
$this->cleanupInterval = $cleanupInterval;
}
`
with this code, I can export as PDF file.
How to fix this issue and not hardcoded core source?
Thank you...
I'm looking to use CSV files as a sort of bulk upload option and was wondering if that's a feature that is planned at all for this package, I know the base Laravel Excel package handles this already.
If it's not planned I will work on my own implementation, if it is planned I would be happy to contribute in some way.
When trying to download a file the browser would display Failed - Server problem
.
Type error: Too few arguments to function Symfony\Component\HttpFoundation\BinaryFileResponse::deleteFileAfterSend(), 0 passed in vendor/maatwebsite/laravel-nova-excel/src/Http/Controllers/ExcelController.php on line 31 and exactly 1 expected
Running on Mac, Valet with Laravel 5.6.
Hi!
Firstly, great product. It's been an absolute time-saver for some of our projects.
In the normal version of the Excel lib, we can merge some of the output columns together but have looked through the docs and source, it doesn't seem to be possible in the Nova version - is that correct?
If Select All Matching action not display but Select All it 's work
Hi,
When trying to Export to Excel (via a Lens), I am seeing an error:
array_flip(): Can only flip STRING and INTEGER values!
any thoughts what can cause this?
I get an error when starting the download action.
I used the quick instructions and installed the package.
Added an action to one of my entities.
When I press download, I receive a message
"Malformed UTF-8 characters, possibly incorrectly encoded"
P.S.
In the database I use Cyrillic
Resource index page displays a computed field from the original field. In this case, was adding an anchor tag to the email field using the Nova's method displayUsing()
.
Expected behavior:
Exporting to excel should use the original field instead of the computed one.
Actual behavior:
Exported field is exported with the computed format (eg. html tag)
Since it is usefull in some cases to export the computed fields, maybe we could have an option to toggle this behaviour either to a single or multiple columns.
I've got a kubernetes setup running with Laravel in a container. The containers work fine with Nova and the excel package in general when you have 1 container running. However we have multiple containers running behind a load balancer.
The problem we have with this is that whenever we download the excel sheet or csv using the action from this package we receive a failed download. This is because the download is created in the /tmp
directory in one controller and downloaded from a different controller.
The reason for this is the setup of how downloads work. Whenever you perform an action regarding downloading the download url is returned with the path and file name
download: "https://local.site.com/nova-vendor/maatwebsite/laravel-nova-excel/download?path=%2Ftmp%2Flaravel-excel-SzURRyYeVGglGtCWrrnie7NzfdidTJKi&filename=users-1562309499.csv"
name: "users-1562309499.csv"
After the response has been received in Nova the download is being called from the url. In our case this means the load balancer might take a different container and the download fails.
Note: I'm not sure if this problem lays in this package or Nova, but it surely isn't ideal!
So my actual question now! Is it possible to store the file somewhere else before downloading it. So somewhere local S3 or another directory than /tmp
. Does this package provide functionality for that?
Not sure if I can provide this easily, but I can thing along if you need more info
Expected behavior:
Actual behavior:
/tmp
directory of the random picked container.Any additional information, configuration or data that might be necessary to reproduce the issue.
On exporting ~3K subscriptions
records via a QueuedExport we get an SQL exception:
Communication link failure: 1153 Got a packet bigger than 'max_allowed_packet' bytes (SQL: insert into `jobs` (`queue`, `attempts`, `reserved_at`, `available_at`, `created_at`, `payload`)
We are using the database
driver in combination with php artisan queue:work --tries=5 --delay=5
The Subscription
Nova Resource looks like:
public function fields(Request $request)
{
return [
ID::make()
->hideFromIndex(),
BelongsTo::make('User', 'user', \App\Nova\Resources\User\User::class),
Text::make('Stripe id'),
Text::make('Initial source')
->hideFromIndex(),
DateTime::make('End date')
->sortable(),
DateTime::make('Cancelation requested at')
->sortable(),
DateTime::make('Canceled at')
->sortable(),
Code::make('Import data')
->json()
->hideFromIndex(),
DateTime::make('Created at')
->sortable()
->hideFromIndex(),
HasMany::make('Payments', 'payments', \App\Nova\Resources\Program\Subscription\SubscriptionPayment::class),
];
}
public function actions(Request $request)
{
$filename = 'exports/subscriptions/subscriptions-' . Carbon::now() . '.xlsx';
$disk = 's3';
return [
(new ExportSubscription)
->withFilename($filename)
->withDisk($disk)
->withChunkCount(1000)
->onSuccess(function (ActionRequest $request, PendingDispatch $queue) use ($filename, $disk) {
$queue->chain([
new NotifyAdminOfCompletedExport($request->user(), $filename, $disk),
]);
return Action::message('The export is being created, when done it will be send via email to '.$request->user()->email);
}),
];
}
The ExportSubscription looks like:
class ExportSubscription extends QueuedExport implements WithMapping, WithHeadings
{
/**
* Headers
*
* @return array
*/
public function headings(): array
{
return [
'ID',
'External ID',
'Name',
'Email',
'Stripe ID',
'Initial source',
'End date',
'Cancelation requested at',
'Canceled at',
'Created at',
];
}
/**
* @param Subscription $subscription
*
* @return array
*/
public function map($subscription): array
{
return [
$subscription->id,
$subscription->user ? $subscription->user->external_id : null,
$subscription->user ? $subscription->user->name : null,
$subscription->user ? $subscription->user->email : null,
$subscription->stripe_id,
$subscription->initial_source,
$subscription->end_date ? $subscription->end_date : null,
$subscription->cancelation_requested_at ? $subscription->cancelation_requested_at : null,
$subscription->canceled_at ? $subscription->canceled_at : null,
$subscription->created_at ? $subscription->created_at : null,
];
}
}
When I check the payload
column it is stacked with information that is not my $subscription
or $subscription->user
for example (small excerpt):
O:55:\"Maatwebsite\\LaravelNovaExcel\\Requests\\SerializedRequest\":3:{s:66:\"\u0000Maatwebsite\\LaravelNovaExcel\\Requests\\SerializedRequest\u0000className\";s:65:\"Maatwebsite\\LaravelNovaExcel\\Requests\\ExportResourceActionRequest\";s:65:\"\u0000Maatwebsite\\LaravelNovaExcel\\Requests\\SerializedRequest\u0000resource\";s:13:\"subscriptions\";s:61:\"\u0000Maatwebsite\\LaravelNovaExcel\\Requests\\SerializedRequest\u0000lens\";N;}s:11:\"\u0000*\u0000resource\";s:52:\"App\\Nova\\Resources\\Program\\Subscription\\Subscription\";s:22:\"\u0000*\u0000serializedResources\";a:43854:{i:0;s:35:\"Laravel\\Nova\\Actions\\ActionResource\";i:1;s:35:\"Laravel\\Nova\\Actions\\ActionResource\";i:2;s:30:\"App\\Nova\\Resources\\Admin\\Admin\";i:3;s:32:\"App\\Nova\\Resources\\Clinic\\Clinic\";i:4;s:36:\"App\\Nova\\Resources\\Clinic\\ClinicUser\";i:5;s:31:\"App\\Nova\\Resources\\Course\\Block\";i:6;s:32:\"App\\Nova\\Resources\\Course\\Course\";i:7;s:36:\"App\\Nova\\Resources\\Course\\CourseUser\";i:8;s:34:\"App\\Nova\\Resources\\Course\\Exercise\";i:9;s:34:\"App\\Nova\\Resources\\Course\\Location\";i:10;s:33:\"App\\Nova\\Resources\\Course\\Message\";i:11;s:33:\"App\\Nova\\Resources\\Course\\Workout\";i:12;s:29:\"App\\Nova\\Resources\\Discipline\";i:13;s:23:\"App\\Nova\\Resources\\Link\";i:14;s:27:\"App\\Nova\\Resources\\Material\";i:15;s:32:\"App\\Nova\\Resources\\Program\\Block\";i:16;s:35:\"App\\Nova\\Resources\\Program\\Exercise\";i:17;s:34:\"App\\Nova\\Resources\\Program\\Program\";i:18;s:38:\"App\\Nova\\Resources\\Program\\ProgramUser\";i:19;s:45:\"App\\Nova\\Resources\\Program\\ProgramUserWorkout\";i:20;s:52:\"App\\Nova\\Resources\\Program\\Subscription\\Subscription\";i:21;s:59:\"App\\Nova\\Resources\\Program\\Subscription\\SubscriptionPayment\";i:22;s:32:\"App\\Nova\\Resources\\Program\\Theme\";i:23;s:34:\"App\\Nova\\Resources\\Program\\Workout\";i:24;s:34:\"App\\Nova\\Resources\\User\\Onboarding\";i:25;s:28:\"App\\Nova\\Resources\\User\\User\";i:26;s:24:\"App\\Nova\\Resources\\Video\";i:27;s:35:\"Laravel\\Nova\\Actions\\ActionResource\";i:28;s:30:\"App\\Nova\\Resources\\Admin\\Admin\";i:29;s:32:\"App\\Nova\\Resources\\Clinic\\Clinic\";i:30;s:36:\"App\\Nova\\Resources\\Clinic\\ClinicUser\";i:31;s:31:\"App\\Nova\\Resources\\Course\\Block\";i:32;s:32:\"App\\Nova\\Resources\\Course\\Course\";i:33;s:36:\"App\\Nova\\Resources\\Course\\CourseUser\";i:34;s:34:\"App\\Nova\\Resources\\Course\\Exercise\";i:35;s:34:\"App\\Nova\\Resources\\Course\\Location\";i:36;s:33:\"App\\Nova\\Resources\\Course\\Message\";i:37;s:33:\"App\\Nova\\Resources\\Course\\Workout\";i:38;
I would not expect App\Nova\Resources\Admin\Admin
and App\Nova\Resources\Program\Block
etc in there. It looks like it's serializing the entire Nova Object every time and appending it?
We played around with withChunkCount($i)
and it helps a bit, but seems like a temporary fix, after more records in the database it started happening again.
Is there something we can do to optimize the serializing? Send less data to the queue?
Hi, after updating I had the following error:
Argument 2 passed to Maatwebsite\LaravelNovaExcel\Actions\ExportToExcel::replaceFieldValuesWhenOnResource() must be of the type array, null given, called in /Users/danieljones/Dev/newforest-rustic-furniture/vendor/maatwebsite/laravel-nova-excel/src/Actions/ExportToExcel.php on line 242 {"userId":1,"email":"[email protected]","exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): Argument 2 passed to Maatwebsite\LaravelNovaExcel\Actions\ExportToExcel::replaceFieldValuesWhenOnResource() must be of the type array, null given, called in /Users/danieljones/Dev/newforest-rustic-furniture/vendor/maatwebsite/laravel-nova-excel/src/Actions/ExportToExcel.php on line 242 at /Users/danieljones/Dev/newforest-rustic-furniture/vendor/maatwebsite/laravel-nova-excel/src/Actions/ExportToExcel.php:282)
[stacktrace]
I am now running version 1.1.0 up from 1.0.6.
The export picks up on translated fields like this:
public function fields(Request $request)
{
return [
Text::make(__('Company'), 'company'),
Text::make(__('Lastname'), 'lastname')->sortable()
->rules('required', 'max:255'),
Text::make(__('Firstname'), 'firstname')
]
}
They show up translated in the excel file, but only when they are on the index. For fields that are excluded from the index no translation is shown.
When trying to do a queued export (tried with both database and redis) it fails silently without throwing any error or having any failed jobs. After investigating further the queue processing stops at
Processing: Maatwebsite\Excel\Jobs\AppendQueryToSheet i opened the logs (when using the database driver) and i saw the error communication link failure: 1153 Got a packet bigger than max_allowed_packet bytes. From what i understand it tries to serialize a huge request object and fails.
Expected behavior:
Queue excel exports
Actual behavior:
Excel export queuing fails everytime no matter how large the selected dataset is.
Any help will be greatly appreciated thanks in advance!
Wrong order of columns in exported excel
(new DownloadExcel)
->only([
'title',
'first_name',
'last_name',
'email'
])
->withHeadings([
'Title',
'Vorname',
'Nachname',
'E-Mail'
])
->askForWriterType()
Expected behavior:
Order of Data Excel file is: title, first_name, last_name, email
Actual behavior:
Order of Data Excel file is: first_name, last_name, title, email
Order of headings is correct though.
I think the problem is in vendor/maatwebsite/laravel-nova-excel/src/Actions/ExportToExcel.php in replaceFieldValuesWhenOnResource() where the 'resourceFields' are always used first and then the 'only' fields.
protected function replaceFieldValuesWhenOnResource(Model $model, array $only = []): array
{
...
// Fix sorting
$row = array_merge(array_flip($only), $row);
return $row;
}
or
protected function replaceFieldValuesWhenOnResource(Model $model, array $only = []): array
{
...
// Fix sorting
uksort($row, function($key1, $key2) use ($only) {
return (array_search($key1, $only) > array_search($key2, $only));
});
return $row;
}
When i try to export file, content is Javascript content
Expected behavior:
My data exported
Actual behavior:
Javascript code inside content
On my project i have json editor plugin loaded (cf: https://github.com/json-editor/json-editor). it seems it's Jsoneditor in content file. Maybe it's a conflict ?
When you select all and then export, will it be all records in the database or just all records shown in the current page?
Hi guys,
Just a quick heads up, upgrading Nova to 2.1 fails because of this package does not support it yet.
I am having this same issue. It just says "Failed - No File" in chrome. I have added the package manually in app.php, although auto discovery is on in my project, but still nothing. The response I get back from the package is:
download: "http://reflect.test/nova-vendor/maatwebsite/laravel-nova-excel/download?path=%2Fprivate%2Fvar%2Ftmp%2Flaravel-excel-9kHdcVh2sPrFf2vYUdgTsLmVpVW304ct&filename=users.csv"
name: "users.csv"
Followed installation guide
Clicked 1 user to download CSV or XLS file
Click Action Button
File download fails
Tried fix from issue #11 but did not work.
File to be downloaded
Actual behavior:
Error downloading. Says no file and the link in the response returns a 404
Using allFields()
method breaks export of relationship and computed fields.
Ensure that your Resource includes a field that is defined with a BelongsTo
relationshipβ¦
BelongsTo::make('User'),
β¦or field that returns a computed valueβ¦
Text::make('Random number', function () {
return str_random();
}),
Use the allFields()
method on the action as described in the documentationβ¦
public function actions(Request $request)
{
return [
(new DownloadExcel)->allFields(),
];
}
Expected behavior:
The exported file should contain a representation of the relationship similar to how it appears on the Nova Resource index page. Similarly the file should contain the output generated by closure defined on the computed field.
Actual behavior:
The related record is represented in the Excel file as a foreign key. Computed fields are omitted.
This is already a known issue as indicated by a common made on a previous issue.
Are you using
->allFields()
perhaps?
Originally posted by @patrickbrouwers in #26 (comment)
Given that the dev team has been aware of this since at least November 2018 I assume it is difficult or impractical to fix. However it would be useful to have this βfeatureβ documented on the "Customizing Exportsβ page of the documentation and anywhere else that may be relevant.
The following error prevents lenses from being downloaded when joins & aggregation.
It seems the download action isn't using an identical query for lenses maybe
Make a query that doesn't group by the parent id
This lens is attached to an "orders" resource
And it gets the number of orders and the sum
The order id is unrelated and excluded
Which does not pose an issue for nova lenses
public static function query(LensRequest $request, $query)
{
return $request->withOrdering($request->withFilters(
$query
// ->select('orders.id')
->addSelect('teams.name as team_name')
->addSelect(\DB::raw('count(orders.id) as orders_count'))
->addSelect(\DB::raw('sum(orders.total) as spend'))
->join('teams', 'orders.team_id', '=', 'teams.id')
->groupBy('teams.id')
));
}
Expected behavior:
Export the table with a join, aggregate & group by
Actual behavior:
Throws exception stating parent table id isn't included in the group by
[2018-09-28 10:02:29] local.ERROR: SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'databasename.orders.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by (SQL: select `teams`.`name` as `team_name`, count(orders.id) as orders_count, sum(orders.total) as spend from `orders` inner join `teams` on `orders`.`team_id` = `teams`.`id` where `orders`.`id` in () group by `teams`.`id` order by `orders`.`id` asc limit 200 offset 0)
A lens is a report table. Not always will the id be assumed.
Most cases it will likely not be.
Computed fields are only included for certain resources, but not others. Haven't been able to determine why.
Example:
Expected behavior:
All the field values to be added into the export.
Actual behavior:
Computed fields not properly added into the export.
This seems to happen when there's pagination involved (exporting about 200 items)
When using Firefox and running the DownloadExcel action no file is downloaded.
I am using 64.0a1 (2018-09-10) (64-bit) which is the nightly version which might be the problem. I donβt have the release version for testing.
Thanks for this package, it's Awesome.
I want to ask you, if the package can export relation fields like (author name for the post), or is it planned?
When exporting the sort order of the overview is not kept. This makes exporting large lists quite hard.
Resource with 200 records, order by a value, set per page to 100, download.
Expected behavior:
Download the top 100 (in order)
Actual behavior:
It downloads the 10 ordered by ID
Hello, thanks for this great package.
When I am asking to export all attributes from a resource like follows:
public function actions(Request $request)
{
return [
(new DownloadExcel())->allFields()->withHeadings();
];
}
it fails to export attributes with empty value. This consequently mangles the export data with mismatched column/data.
For example, if the a resource in database has the following rows:
+----+------------+------+---------------------+---------------------+
| id | brand | year | created_at | updated_at |
+----+------------+------+---------------------+---------------------+
| 1 | Alfa Romeo | 2018 | 2018-12-14 08:43:51 | 2018-12-14 08:43:51 |
| 2 | Audi | NULL | 2018-12-14 08:44:10 | 2018-12-14 08:45:05 |
+----+------------+------+---------------------+---------------------+
and I am using the following Nova resource fields (you see Year
is not an index field):
public function fields(Request $request)
{
return [
ID::make()->sortable(),
Text::make('Brand'),
Number::make('Year')->onlyOnForms()
];
}
will eventually export:
ID,Brand,year,created_at,updated_at
1,Alfa Romeo,2018,2018-12-14 08:43:51,2018-12-14 08:43:51
2,Audi,2018-12-14 08:44:10,2018-12-14 08:45:05
First row has 5 columns but 2nd row has 4 columns.
Debugging the code, I see that this line:
prevents to export attribute if it is empty.
Similar problem is referenced in #18 and #19.
Problem
QueuedExport
of a hasMany
related model. In our case, we have Clients
hasMany Documents
and we would like to export the Documents
under the Client
view. The parameters that we used are:return (new QueuedExport)
->withDisk('s3')
->withHeadings()
->withChunkCount(200);
AppendQueryToSheet
job appears to be returning an error. The error appears to trace to $row
on map($row)
being an object and not an array.Diagnosis
If we turn the $row object into an array (e.g. $row = (array) $row;
), the queued export works also as normal. (I did this directly on the vendor file as a hack to test)
https://github.com/Maatwebsite/Laravel-Nova-Excel/blob/806cafa2cf38de9a8f6c8cbc835445f406148b69/src/Actions/ExportToExcel.php#L227,
If we change the action from QueuedExport
to ExportToExcel
, the export works so the issue appears to lie in the queueing mechanic.
Note: Exports on the Document resource works perfectly fine. Itβs only an issue when expiring Documents from the Client resource view.
Any assistance is appreciated.
Version Used
Laravel-Nova-Excel: v1.10
Laravel: 5.7
PHP: 7.2
I spent the last few hours troubleshooting why some fields weren't showing up in my exports. After a while, I found out that Laravel Nova Excel
makes the query into a model, at which point the protected $hidden
property of the model stripped away the fields I was requesting with only()
.
To avoid this issue, I suggest looping through the items in the only()
list and setting those manually on the model. That will allow people to hide items in other places of in the code. (Ex. Sending models to JSON format as discussed in the official Laravel docs) It'll also allow people to export that which they'd like to export.
Not sure if this is pilot error, or a bug. Installing nova-excel with composer fails on dependencies. Installing 'maatwebsite/excel' via composer and then installing nova-excel appears to be a bandaid.
Using version ^1.0 for maatwebsite/laravel-nova-excel
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- maatwebsite/laravel-nova-excel 1.0.0 requires maatwebsite/excel ^3.0 -> satisfiable by maatwebsite/excel[3.0.x-dev].
- maatwebsite/laravel-nova-excel 1.0.1 requires maatwebsite/excel ^3.0.10 -> satisfiable by maatwebsite/excel[3.0.x-dev].
- maatwebsite/laravel-nova-excel 1.0.x-dev requires maatwebsite/excel ^3.0.10 -> satisfiable by maatwebsite/excel[3.0.x-dev].
- Conclusion: don't install maatwebsite/excel 3.0.x-dev
- Installation request for maatwebsite/laravel-nova-excel ^1.0 -> satisfiable by maatwebsite/laravel-nova-excel[1.0.0, 1.0.1, 1.0.x-dev].
and installing maatwebsite/excel first:
Using version ^3.0 for maatwebsite/excel
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 3 installs, 1 update, 0 removals
- Installing markbaker/complex (1.4.6): Loading from cache
- Installing phpoffice/phpspreadsheet (1.4.0): Loading from cache
- Updating maatwebsite/excel (2.1.29 => 3.0.10): Downloading (100%)
- Installing maatwebsite/laravel-nova-excel (1.0.1): Downloading (100%)
phpoffice/phpspreadsheet suggests installing mpdf/mpdf (Option for rendering PDF with PDF Writer)
phpoffice/phpspreadsheet suggests installing dompdf/dompdf (Option for rendering PDF with PDF Writer)
phpoffice/phpspreadsheet suggests installing tecnick.com/tcpdf (Option for rendering PDF with PDF Writer)
phpoffice/phpspreadsheet suggests installing jpgraph/jpgraph (Option for rendering charts, or including charts with PDF or HTML Writers)
Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover
Discovered Package: arsenaltech/nova-tab
Discovered Package: fideloper/proxy
Discovered Package: laravel/nova
Discovered Package: laravel/tinker
Discovered Package: maatwebsite/excel
Discovered Package: maatwebsite/laravel-nova-excel
Discovered Package: nickfairchild/nova-at-a-glance-card
Discovered Package: nunomaduro/collision
Discovered Package: owen-it/laravel-auditing
Package manifest generated successfully.```
$ composer require maatwebsite/laravel-nova-excel
Using version ^1.0 for maatwebsite/laravel-nova-excel
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating optimized autoload files
Illuminate\Foundation\ComposerScripts::postAutoloadDump
@php artisan package:discover
Discovered Package: arsenaltech/nova-tab
Discovered Package: fideloper/proxy
Discovered Package: laravel/nova
Discovered Package: laravel/tinker
Discovered Package: maatwebsite/excel
Discovered Package: maatwebsite/laravel-nova-excel
Discovered Package: nickfairchild/nova-at-a-glance-card
Discovered Package: nunomaduro/collision
Discovered Package: owen-it/laravel-auditing
Package manifest generated successfully.```
Laravel Nova Excel allows you to gain full control over your resource exports, and you can choose to create your own actions:
https://docs.laravel-excel.com/nova/1.1/exports/customizations.html#full-control
I added an action field and it worked, it's asking me for a value.
https://nova.laravel.com/docs/1.0/actions/defining-actions.html#action-fields
However when I add the handle() method to access the field I get a signature problem and I'm not sure what to do.
Return type declaration must be compatible with DownloadExcel->handle(request : \Laravel\Nova\Http\Requests\ActionRequest, exportable : \Laravel\Nova\Actions\Action) : array
Hi,
I have a simple resource with three fields and when I try to Download the excel. I get this message
Invalid argument supplied for foreach()
When I the code this variable is always null in the ExportToExcel class :
$this->actionFields;
Install the package, add the action in the resource and test to Download Excel.
I have try on different resources and same bug each time.
If in the package when I try to change the ExportExcel class and replace the
return $this->actionFields;
by this it's work
return [];
First of al, great package, just what I needed! ππ€
I keep getting a problem with some basic resources (whereas others work perfectly).
This is the error message:
Undefined offset: 0 at /Users/***/Workspace/***/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/DefaultValueBinder.php:56
My actions look like this:
public function actions(Request $request)
{
return [
(new DownloadExcel())->withHeadings('#', 'description')
];
}
The columns does exist in the database, there is also no difficult eagerloading or anything else involved, its just a (really) basic orders table with id, description, total, user_id and timestamps.
More stacktrace:
[2018-08-31 05:56:19] local.ERROR: Undefined offset: 0 {"userId":1,"email":"[email protected]","exception":"[object] (ErrorException(code: 0): Undefined offset: 0 at /Users/***/Workspace/***/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/DefaultValueBinder.php:56)
[stacktrace]
#0 /Users/***/Workspace/***/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/DefaultValueBinder.php(56): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(8, 'Undefined offse...', '/Users/***...', 56, Array)
#1 /Users/***/Workspace/***/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/DefaultValueBinder.php(34): PhpOffice\\PhpSpreadsheet\\Cell\\DefaultValueBinder::dataTypeForValue(Array)
#2 /Users/***/Workspace/***/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Cell.php(184): PhpOffice\\PhpSpreadsheet\\Cell\\DefaultValueBinder->bindValue(Object(PhpOffice\\PhpSpreadsheet\\Cell\\Cell), Array)
#3 /Users/***/Workspace/***/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Worksheet/Worksheet.php(2508): PhpOffice\\PhpSpreadsheet\\Cell\\Cell->setValue(Array)
#4 /Users/***/Workspace/***/vendor/maatwebsite/excel/src/Sheet.php(208): PhpOffice\\PhpSpreadsheet\\Worksheet\\Worksheet->fromArray(Array, NULL, 'A13', false)
Hey.
Is it possible to, in your own custom Action, get the models from the selected overview?
The Action documentation dictates that you can typehint it, but that's not possible because it would violate the DownloadExcel contract.
You can see the section of the docs here: https://nova.laravel.com/docs/1.0/actions/defining-actions.html#action-responses
I'd like to create a sheet per. model, and just use the first-sheet as a summary of the models.
How would I go about that?
I have the following in my actions()
function:
return [
(new DownloadExcel())
->withFilename('documents')
->askForWriterType([
Excel::XLSX => 'XLSX',
Excel::CSV => 'CSV',
Excel::HTML => 'HTML',
])
];
Instead of getting the filename I set within withFilename
function followed by the extesion I selected in the dropdown menu, I get only documents
without any extesion.
This is happening only when askForWriterType
is used in combination with withFilename
function.
I have seen in the documentation that when using withFilename
, I should specify the file extension within the function parameter, like withFilename('documents.html')
, but the file type beeing dynamic, how I can get what file type the user selected within the dropdown menu?
Just add the above code in your Nova component.
Expected behavior:
The name of the file I want to download should be documents.
followed by the extesion I selected in the dropdown list. For example, if I select html
, I should get documents.html
.
Actual behavior:
Instead of getting the filename I set within withFilename
function followed by the extesion I selected in the dropdown menu, I get only documents
without any extesion.
Hi! Thank you for this time saver plugin. I have a question about his behaviour: i'm looking for export in excel a nova resource called that is a report with a lot of fields that are connected with foreign keys to other tables. Now in my nova resource page i can see the description of each row connected with keys in my report but if i click export to excel i have a single row with only foreign keys: can i have instead the description like in browser?
Create a resource in relation with others and add a relation field (like BelongsTo)
Expected behavior:
Show description of related resource
Actual behavior:
Show the foreign key to related resource
Got this error while exporting one of our Nova resources to Excel through the action:
preg_match() expects parameter 2 to be string, array given at /home/insense/PHP_GIT/prj/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/DefaultValueBinder.php:62)
[stacktrace]
#0 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(2, 'preg_match() ex...', '/home/insense/PHP_...', 62, Array)
#1 /home/insense/PHP_GIT/prj/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/DefaultValueBinder.php(62): preg_match('/^[\\\\+\\\\-]?(\\\\d+\\\\....', Array)
#2 /home/insense/PHP_GIT/prj/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/DefaultValueBinder.php(34): PhpOffice\\PhpSpreadsheet\\Cell\\DefaultValueBinder::dataTypeForValue(Array)
#3 /home/insense/PHP_GIT/prj/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Cell.php(184): PhpOffice\\PhpSpreadsheet\\Cell\\DefaultValueBinder->bindValue(Object(PhpOffice\\PhpSpreadsheet\\Cell\\Cell), Array)
#4 /home/insense/PHP_GIT/prj/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Worksheet/Worksheet.php(2508): PhpOffice\\PhpSpreadsheet\\Cell\\Cell->setValue(Array)
#5 /home/insense/PHP_GIT/prj/vendor/maatwebsite/excel/src/Sheet.php(208): PhpOffice\\PhpSpreadsheet\\Worksheet\\Worksheet->fromArray(Array, NULL, 'A1', false)
#6 /home/insense/PHP_GIT/prj/vendor/maatwebsite/excel/src/Sheet.php(359): Maatwebsite\\Excel\\Sheet->append(Array, 'A1', false)
#7 /home/insense/PHP_GIT/prj/vendor/maatwebsite/excel/src/Sheet.php(178): Maatwebsite\\Excel\\Sheet->appendRow(Array, Object(Maatwebsite\\LaravelNovaExcel\\Actions\\DownloadExcel))
#8 /home/insense/PHP_GIT/prj/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php(39): Maatwebsite\\Excel\\Sheet->Maatwebsite\\Excel\\{closure}(Object(Illuminate\\Database\\Eloquent\\Collection), 1)
#9 /home/insense/PHP_GIT/prj/vendor/maatwebsite/excel/src/Sheet.php(180): Illuminate\\Database\\Eloquent\\Builder->chunk(200, Object(Closure))
#10 /home/insense/PHP_GIT/prj/vendor/maatwebsite/excel/src/Sheet.php(117): Maatwebsite\\Excel\\Sheet->fromQuery(Object(Maatwebsite\\LaravelNovaExcel\\Actions\\DownloadExcel), Object(PhpOffice\\PhpSpreadsheet\\Worksheet\\Worksheet))
#11 /home/insense/PHP_GIT/prj/vendor/maatwebsite/excel/src/Writer.php(97): Maatwebsite\\Excel\\Sheet->export(Object(Maatwebsite\\LaravelNovaExcel\\Actions\\DownloadExcel))
#12 /home/insense/PHP_GIT/prj/vendor/maatwebsite/excel/src/Excel.php(126): Maatwebsite\\Excel\\Writer->export(Object(Maatwebsite\\LaravelNovaExcel\\Actions\\DownloadExcel), 'Xls')
#13 /home/insense/PHP_GIT/prj/vendor/maatwebsite/excel/src/Excel.php(80): Maatwebsite\\Excel\\Excel->export(Object(Maatwebsite\\LaravelNovaExcel\\Actions\\DownloadExcel), 'campaigns.xls', 'Xls')
#14 /home/insense/PHP_GIT/prj/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(223): Maatwebsite\\Excel\\Excel->download(Object(Maatwebsite\\LaravelNovaExcel\\Actions\\DownloadExcel), 'campaigns.xls', 'Xls')
#15 /home/insense/PHP_GIT/prj/vendor/maatwebsite/laravel-nova-excel/src/Actions/DownloadExcel.php(23): Illuminate\\Support\\Facades\\Facade::__callStatic('download', Array)
#16 /home/insense/PHP_GIT/prj/vendor/maatwebsite/laravel-nova-excel/src/Actions/ExportToExcel.php(89): Maatwebsite\\LaravelNovaExcel\\Actions\\DownloadExcel->handle(Object(Laravel\\Nova\\Http\\Requests\\ActionRequest), Object(Maatwebsite\\LaravelNovaExcel\\Actions\\DownloadExcel))
#17 /home/insense/PHP_GIT/prj/nova/src/Http/Controllers/ActionController.php(38): Maatwebsite\\LaravelNovaExcel\\Actions\\ExportToExcel->handleRequest(Object(Laravel\\Nova\\Http\\Requests\\ActionRequest))
#18 [internal function]: Laravel\\Nova\\Http\\Controllers\\ActionController->store(Object(Laravel\\Nova\\Http\\Requests\\ActionRequest), 'campaigns')
#19 /home/insense/PHP_GIT/prj/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): call_user_func_array(Array, Array)
#20 /home/insense/PHP_GIT/prj/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\\Routing\\Controller->callAction('store', Array)
Digging deeper, we found that this issue is related to: SpartnerNL/Laravel-Excel#873
On further analysis, we found that one of the attributes in the resource is an accessor that we include like so:
/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = ['promo_modes'];
//@return array
public function getPromoModesAttribute()
{
return $someArray;
}
Exporting a model with array accessors results in this error. Is there a workaround to say possibly exclude this field in the exported XLS/CSV?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.