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

Exporting data as Excel #261

Open
fbramato opened this issue Jan 2, 2023 · 3 comments
Open

Exporting data as Excel #261

fbramato opened this issue Jan 2, 2023 · 3 comments

Comments

@fbramato
Copy link

fbramato commented Jan 2, 2023

Hi,

i would use the same query builder syntax to export data as Excel.

For example, calling:

User.
    .where(toRaw(filters.value))
    .orderBy((descending ? '-' : '') + sortBy)
    .export('users.xlsx');

would call /users/export with the same querystring parameters of get() method and then use a snippet similar to

axios.get(url, { responseType: 'blob' })
      .then(response => {
        const blob = new Blob([response.data], { type: 'application/pdf' })
        const link = document.createElement('a')
        link.href = URL.createObjectURL(blob)
        link.download = label
        link.click()
        URL.revokeObjectURL(link.href)

or https://www.npmjs.com/package/file-saver

I'm using https://docs.laravel-excel.com/3.1/exports/ and would be incredibly helpful replicate the same get() behaviour exporting the Excel from

public function export()
    {
        $data = QueryBuilder::for(User::class)
            ->allowedFilters(['soggetto', 'soggetto.nominativo', 'login', 'tipo_utente', 'roles.id'])
            ->allowedIncludes(['soggetto'])
            ->with('soggetto')
            ->get();

        return Excel::download(new UsersExport($data), 'users.xlsx');
    }

Maybe is already possible with some hack :)

Thanks

@fbramato
Copy link
Author

I've opened the PR #266 with the new file() method handling a Blob

@otherperspectives
Copy link

Any updates on this?

@fbramato
Copy link
Author

fbramato commented May 4, 2023

i've forked and internalized the code of this package in my project because i think it's dead as the maintainer is not replying to any issues since a while

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

No branches or pull requests

2 participants