下载没有Headers的xlsx文件,Vuejs
Download xlsx file without Headers, Vuejs
我有一个下载操作,它有效,但在我的 .xlsx 文件中我没有 header,我不确定如何获得它们。我在 Laravel.
中使用 Vuejs / Axios
<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 => {
//
});
},
导出Class代码
namespace App\Exports;
use App\ViewData;
use Maatwebsite\Excel\Concerns\FromCollection;
use Excel;
class DataExport implements FromCollection
{
public function collection()
{
return ViewData::all();
}
}
好吧,你实际上可以这样做
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',
];
}
}
我有一个下载操作,它有效,但在我的 .xlsx 文件中我没有 header,我不确定如何获得它们。我在 Laravel.
中使用 Vuejs / Axios<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 => {
//
});
},
导出Class代码
namespace App\Exports;
use App\ViewData;
use Maatwebsite\Excel\Concerns\FromCollection;
use Excel;
class DataExport implements FromCollection
{
public function collection()
{
return ViewData::all();
}
}
好吧,你实际上可以这样做
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',
];
}
}