Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I export laravel pagination data to Excel ? #44

Closed
ghost opened this issue Aug 12, 2018 · 4 comments
Closed

How can I export laravel pagination data to Excel ? #44

ghost opened this issue Aug 12, 2018 · 4 comments
Labels
question Further information is requested

Comments

@ghost
Copy link

ghost commented Aug 12, 2018

Hello,
at first thanks for this great package,
I wanna know how I can export excel file from Laravel pagination data ?

I mean this is blow:

$items = User->where('active',1)->orderBy('position','desc')->paginate(10);
$data = $items->toArray()['data'];
return (new FastExcel($data))->download('file.xlsx');

because of I want to export excel file per page
I hope you help me as soon as you read it ...

@ghost ghost changed the title how can I export laravel pagination data to excel? How can I export laravel pagination data to Excel ? Aug 12, 2018
@rap2hpoutre
Copy link
Owner

Hi, thank you!

I'm not sure I understand your need. Do you want to:

  1. export one sheet for each page (let's say: "sheet 1 -> users from 1 to 50", "sheet 2 -> users from 51 to 100", etc.)?
  2. or export only the users returned by the paginate method?
  3. or something else (in this case could you please elaborate)?

@ghost
Copy link
Author

ghost commented Aug 18, 2018

Thanks for answering , but I mean that how I can use pagination data result for exporting, as you know , Laravel pagination merhod every time return object includes "data" key and I couldn't access that ,
I wanna how I can get "data" as a collection for using in new FastExcel($data) ?

@rap2hpoutre
Copy link
Owner

rap2hpoutre commented Sep 5, 2018

Sorry for the delay!

I just tested and I think I understood the problem: you need to convert the array to a collection, just like this:

$items = User::paginate(10);
$data = collect($items->toArray()['data']); // <- collect the data here.
return (new FastExcel($data))->download('file.xlsx');

I hope it's not too late for you! Let me know if you have any more question!

@rap2hpoutre rap2hpoutre added the question Further information is requested label Sep 5, 2018
@rap2hpoutre
Copy link
Owner

@webcoweb Did it fix your issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant