1

I have a download action, that it works, but in my .xlsx file I don't have the header, and I am not sure how can I get them. I'm using Vuejs / Axios with Laravel.

<a type="button" class="mr-3" href="/json/persons/export" download="file.xlsx">
<button @click="exportCSV" class="btn btn-primary">
    Export CSV
</button>
</a>

exportCSV() {
    axios
    .get("/json/persons/export", {
        params: {
        sort_by: this.sortBy,
        sort_direction: this.sortDesc
        }
    })
    .then(response => {
        //
    })
    .catch(error => {
        //
    });
},

Export Class Code

namespace App\Exports;
use App\ViewData;
use Maatwebsite\Excel\Concerns\FromCollection;
use Excel;

class DataExport implements FromCollection
{
    public function collection()
    {
        return ViewData::all();
    }

}
0

1 Answer 1

1

Well you can actually do something like

namespace App\Exports;
use App\ViewData;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Excel;

class DataExport implements FromCollection, WithHeadings
{
    public function collection()
    {
        return ViewData::all();
    }

    //Define your desired headings this way, it's just for an example
    public function headings(): array
    {
       return [
           'Name',
           'Surname',
           'Email',
           'Twitter',
       ];
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

Best, thank's a lot! Ps. I think that you should place an answer to the other question.
Yeah let me place answer to the question as well. Welcome
Posted that answer to your question too. please check that as well

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.